Hi, can you give us the ds definition please?
- Romain 2011/11/18 og0815 <[email protected]> > I was wondering if the following behavior is as expected or wrong. > Consider the following code: > > <persistence version="2.0" > > <persistence-unit name="pu" transaction-type="RESOURCE_LOCAL"> > <provider>org.hibernate.ejb.HibernatePersistence</provider> > <jta-data-source>ds</jta-data-source> > <non-jta-data-source>dsu</non-jta-data-source> > <exclude-unlisted-classes>false</exclude-unlisted-classes> > </persistence-unit> > </persistence> > > @Entity > public class Person implements Serializable { > > @Id > @GeneratedValue > private int id; > > private String name; > > private int age; > > public Person() {} > > public Person(String name, int age) { > this.name = name; > this.age = age; > } > } > > > @Stateless > // @TransactionManagement(TransactionManagementType.BEAN) > public class ImportantService { > > @PersistenceUnit(unitName="pu") > private EntityManagerFactory emf; > > public void doSomething() { > EntityManager em = emf.createEntityManager(); > em.getTransaction().begin(); > em.persist(new Person("Hans", 12)); > em.persist(new Person("Hugo", 22)); > em.persist(new Person("Horst", 43)); > em.getTransaction().commit(); > em.close(); > } > > } > > Now if you use it in a test, openejb honers you with an exception that ends > up with: > java.sql.SQLException: Commit can not be set while enrolled in a > transaction > > Removing em.getTransaction().commit(); solves everything. > > On the other hand if you uncomment the line > // @TransactionManagement(TransactionManagementType.BEAN) > Everything works also fine. > > So I understand, that if you work with RESOURCE_LOCAL in the JPA > implementation, the Container still manages the transaction in the way, > that > he expects them to be begun but closes all of them by himself. > > Only if you add the @TransactionManagement(TransactionManagementType.BEAN) > you get complete control over your transaction. > > Now my question is, is this behavior correct ? As far as I understood the > docs, if you use a RESOURCE_LOCAL PU you are always responsible for > beginning and committing the transaction. > So setting @TransactionManagement(TransactionManagementType.BEAN) should > have no effect. > Or am I getting the docs wrong and the behavior is correct ? > > Tested with openejb 4.0.0-beta-1 and beta-2-SNAPSHOT. > > Regards, > Olli > > > > > -- > View this message in context: > http://openejb.979440.n4.nabble.com/RESOURCE-LOCAL-and-TransactionManagementType-BEAN-tp4084074p4084074.html > Sent from the OpenEJB User mailing list archive at Nabble.com. >
