TransactionRequiredException jpacontainer 3.0.0-alpha1

hi,

we’re trying out the new vaadin version with jpacontainer and cdi-plugin ( Vaadin 7.0.0.beta8, JPA-Container 3.0.0-alpha1 )

We use JBoss configured with eclipselink… and we’ve followed the instructions in mattis blog:

Mattis Blog ( Using JPA Container in JEE6 Server )

it’s a little sample project with contacts-table and contacts editor. if i try to save in the editor i get TransactionRequiredException.
do i have to change the EjbEntityProvider? my EjbEntityProvider looks like this:



package de.zad.entityprovider;

import javax.annotation.PostConstruct;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.vaadin.addon.jpacontainer.provider.CachingMutableLocalEntityProvider;

/**
 * 
 * @author heisecke
 * 
 */
@TransactionManagement
public abstract class EjbEntityProvider<T> extends CachingMutableLocalEntityProvider<T> {

	@PersistenceContext(name="persistence/em",unitName="Heisecke")
	protected EntityManager em;
	
    protected EjbEntityProvider(Class entityClass) {
        super(entityClass);
    }

    @PostConstruct
    public void init() {
        setTransactionsHandledByProvider(false);
        setEntityManager(em);
        
        setEntitiesDetached(false);

    }

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    protected void runInTransaction(Runnable operation) {
        super.runInTransaction(operation);
    }


}

let me know, if you need further information!

thank you

Hi,

I haven’t checked at all how JPAContainer could work now with V7. Still I’d suggest you to check the following article that uses JNDI approach. You have to publish your persistency context to JNDI, but otherwise that method makes your code much cleaner. Also transactions might get better handled.

cheers,
matti

thank you… i think you mean this article?
using-jpacontainer-in-jee6-server-is-now-much-simpler
:slight_smile:

i followed the instructions in this tutorial, so that my EjbEntityProvider gets the em with JNDI lookup em = (EntityManager) new InitialContext().lookup(JndiAddresses.DEFAULTS.getEntityManagerName());

and now i get the JPAContainer with

contactContainer = JPAContainerFactory.makeJndi(Contacts.class);

but TransactionRequiredException still appears. can i start a Transaction manualy?

but i do have no influence on editorForm.commit();

thank you