How to configured the PersistenceManager for Bean Managed Transactions?


ebenzacar@...
 

I'm trying to integrate DN (JDO) into my JEE application via the JCA adapter, and configure the Persistence manager to understand BeanManagedTransactions.  I am retrofitting this into existing code (formerly using Kodo), and am having difficulties getting the configuration correct.

In my `persistence.xml` file, I have defined my PU as follows:

    <persistence-unit name="pu">
        <jta-data-source>java:jboss/datasources/POC_DN</jta-data-source>
        <properties>
            <property name="datanucleus.connection.resourceType" value="JTA"/>
            <property name="datanucleus.transaction.type" value="JTA"/>
            <property name="datanucleus.storeManagerType" value="rdbms"/>
            <property name="datanucleus.schema.autoCreateAll" value="false"/>
            <property name="datanucleus.ConnectionFactoryName" value="java:jboss/datasources/POC_DN"/>
 
            <property name="datanucleus.connectionPoolingType" value="dbcp2-builtin"/>
            <property name="javax.persistence.jta-data-source" value="java:jboss/datasources/POC_DN"/>
 
            <property name="datanucleus.jtaLocator" value="jboss"/>
        </properties>
    </persistence-unit>
 

In my Bean code, I my bean is defined as a:     
@TransactionManagement(TransactionManagementType.BEAN)

Finally, in my actual code, I am retrieving the persistence manager from the JNDI and getting the transaction from it (where jndiName is the name of my connection-definition defined in the container)
         PersistenceManagerFactory pmf = (PersistenceManagerFactory) context.lookup(jndiName);
         pm = pmf.getPersistenceManager();
         pm.currentTransaction.begin();
...
...
         pm.currentTransaction.commit();


However, in doing so, I get error messages that I cannot begin a transaction that has already started.  If I omit the begin(), then I get an error message that "IJ031019: You cannot commit during a managed transaction".

In both circumstances, it is clear to me that the PM does not understand that I want to use BeanManagedTransactions.

Is there a special configuration that I need to use?  Is retrieving the PM from the JNDI explicitly like this causing my issues?  How else can I access the Tx statically?  Am I forced/required to retrieve the `java:jboss/UserTransaction` from the JNDI instead?

Thanks for any insight/tips.

Eric


ebenzacar@...
 

As a followup question, does the JCA adapter support anything other than XATransactions?
I see the following in ra.xml:

<transaction-support>XATransaction</transaction-support>

Does it support any other mode?  ie: NoTransaction or LocalTransaction?

Thanks,


Eric


Andy
 

https://www.datanucleus.org/products/accessplatform_5_2/jdo/persistence.html#jboss7 says that "DataNucleus JCA adapter supports both Local and XA transaction types".