tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From og0815 <>
Subject RESOURCE_LOCAL and TransactionManagementType.BEAN
Date Fri, 18 Nov 2011 17:41:15 GMT
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">

public class Person implements Serializable {

    private int id;

    private String name;

    private int age;

    public Person() {}

    public Person(String name, int age) { = name;
        this.age = age;

// @TransactionManagement(TransactionManagementType.BEAN)
public class ImportantService {

    private EntityManagerFactory emf;
    public void doSomething() {
        EntityManager em = emf.createEntityManager();
        em.persist(new Person("Hans", 12));
        em.persist(new Person("Hugo", 22));
        em.persist(new Person("Horst", 43));

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.


View this message in context:
Sent from the OpenEJB User mailing list archive at

View raw message