How to configured the PersistenceManager for Bean Managed Transactions?
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:
<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"/>
In my Bean code, I my bean is defined as a:
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();
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.
As a followup question, does the JCA adapter support anything other than XATransactions?
https://www.datanucleus.org/products/accessplatform_5_2/jdo/persistence.html#jboss7 says that "DataNucleus JCA adapter supports both Local and XA transaction types".