I'm using EclipseLink 2.4.0 in my project, which is a simple web base application running within Tomcat 7.0. I've deployed and configured Bitronix Transaction Manager into Tomcat per the documentation: http://docs.codehaus.org/display/BTM/Tomcat
and I've defined a datasource in Tomcat's JNDI that I can access via the application, Spring specifically.
All the code executes as expected and seems to behave properly but when I attempt to access the database I get an exception from Bitronix, which tells me that I am attempting to access the datasource outside of a transaction.
Caused by: java.sql.SQLException: error enlisting a JdbcConnectionHandle of a JdbcPooledConnection from datasource jdbc/totalTagDataSource in state ACCESSIBLE with usage count 1 wrapping com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection@66869470 on com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@1ae3e881
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at $Proxy29.prepareStatement(Unknown Source)
... 84 more
Caused by: bitronix.tm.internal.BitronixSystemException: resource 'jdbc/totalTagDataSource' cannot be used outside XA transaction scope. Set allowLocalTransactions to true if you want to allow this and you know your resource supports this.
... 95 more
I've defined my transactionManager in Spring as I would usually do and I've annotated my classes so that Spring will perform its transactionManager per the documentation:
But no matter what I try it appears that no transaction is started when accessing the DataSource. Is there something I am missing in EclipseLink or did I not implement something that I should have to allow for EclipseLink to participate in the Global TX?
I managed to identify the issue. It seems that I had a reference to embedded-glassfish container that was causing some class loading issues. Once I removed it as a dependency, I was able to identify the issues with the Spring TX configuration as well as some code that someone checked in that was attempting to perform DB access outside of a global TX. After correcting this the application loads and transactions behave normally.
Again facing the same exception "Internal Exception: java.sql.SQLException: error enlisting a JdbcConnectionHandle of a JdbcPooledConnection from datasource jdbc/totalTagDataSource in state ACCESSIBLE with usage count 1 wrapping". It seems that this exception is not consistent and we are getting this particularly when there are a large number of records to be processed.