Search code examples
java-ee-6openjpaillegalstateexception

IllegalStateException while using UserTransaction (Java EE)


I am trying to make my first Java Enterprise Application and use UserTransactions. Therefore I use JNDI Lookup with java:comp/UserTransaction to get my UserTransaction Object.

public void myMethod(MyEntity e) throws ApplicationException {
    try {
        this.ut = getUserTransaction();
        this.ut.begin();
        this.myStatefulBean.myBusinessMethod(e);
    } catch ...

When I start my Transaction with .begin() and try to invoke any method in my stateful Bean (which works properly before starting a UserTransaction) I get an EJBTransactionRolledbackException which leads me to the following error:

java.lang.IllegalStateException: cannot add non-XA Resource to global JTS transaction

The Bean I am using is annotated with @DataSourceDefinition having className = "org.apache.derby.jdbc.ClientXADataSource" thus there is imo no non-XA Resource. What am I doing wrong?

I am using openjpa 2.2.1, Java EE Version 6


Solution

  • Solved the problem by myself. I used in my DataSourceDefinition name = "java:global/jdbc/testDB" as name, but in my persistence.xml the DataSource name was defined as <jta-data-source>testDB</jta-data-source>

    This seems to work in CMTs but not in a UserTransaction. Correcting the entry in persistence.xml to <jta-data-source>java:global/jdbc/testDB</jta-data-source> fixed the problem.