[please see my email of today for a nicer HTML view of the different issues and patches]
in order to use JPOX via JCA in JBoss 4.0.3 SP1 I had to create some patches due to JBoss being very picky.
In the jpox-ds.xml I configured both ConnectionFactoryName and ConnectionFactory2Name for lookup of Oracle datasources, with ConnectionFactoryName being a local-tx-datasource and ConnectionFactory2Name being a no-tx-datasource (with the latter seeming to result in a autoCommit==true connection). I *didn't* configure Connection(DriverName|URL) etc.
Here's a list of the problems encountered and their fixes:
Must not begin(), commit() or rollback() on Connection that has autoCommit==true
Index: RDBMSManager.java
===================================================================
RCS file: /cvsroot/jpox/JPOX/Core/src/java/org/jpox/store/rdbms/RDBMSManager.java,v
retrieving revision 1.129
diff -u -r1.129 RDBMSManager.java
--- RDBMSManager.java 5 Dec 2005 08:51:34 -0000 1.129
+++ RDBMSManager.java 14 Dec 2005 11:18:46 -0000
@@ -1274,14 +1274,29 @@
boolean success = false;
try
{
- con.commit();
+ if (!con.getAutoCommit()) {
+ con.commit();
+ }
success = true;
}
finally
{
if (!success)
{
- con.rollback();
+ try
+ {
+ if (!con.getAutoCommit()) {
+ con.rollback();
+ }
+ }
+ catch (SQLException e)
+ {
+ String msg=LOCALISER_RDBMS.msg("RDBMS.Manager.POIDConnectionCloseError", e);
+ JPOXLogger.RDBMS_SCHEMA.error(msg);
+ throw new JDODataStoreException(msg);
+ } finally {
+ closeConnection(con);
+ }
}
}
closeConnection(con);
@@ -1893,11 +1908,11 @@
{
if (isolationLevel != Connection.TRANSACTION_NONE)
{
- if (succeeded)
+ if (succeeded && !conn.getAutoCommit())
{
conn.commit();
}
- else
+ else if (!conn.getAutoCommit())
{
conn.rollback();
}
Index: SequenceImpl.java
===================================================================
RCS file: /cvsroot/jpox/JPOX/Core/src/java/org/jpox/SequenceImpl.java,v
retrieving revision 1.12
diff -u -r1.12 SequenceImpl.java
--- SequenceImpl.java 12 Jul 2005 21:51:57 -0000 1.12
+++ SequenceImpl.java 14 Dec 2005 11:20:49 -0000
@@ -106,14 +106,18 @@
boolean success = false;
try
{
- conn.commit();
+ if (!conn.getAutoCommit()) {
+ conn.commit();
+ }
success = true;
}
finally
{
if (!success)
{
- conn.rollback();
+ if (!conn.getAutoCommit()) {
+ conn.rollback();
+ }
}
}
((RDBMSManager)storeManager).closeConnection(conn);
Must not setAutoCommit() within running UserTransaction
Index: DatabaseAdapter.java
===================================================================
RCS file: /cvsroot/jpox/JPOX/Core/src/java/org/jpox/store/rdbms/adapter/DatabaseAdapter.java,v
retrieving revision 1.64
diff -u -r1.64 DatabaseAdapter.java
--- DatabaseAdapter.java 7 Nov 2005 18:28:17 -0000 1.64
+++ DatabaseAdapter.java 14 Dec 2005 11:35:12 -0000
@@ -859,7 +859,9 @@
}
else
{
- conn.setAutoCommit(false);
+ if (conn.getAutoCommit()) {
+ conn.setAutoCommit(false);
+ }
if (supportsTransactionIsolationLevel(isolationLevel))
{
conn.setTransactionIsolation(isolationLevel);
NPE (Core-2604)
Index: PersistenceManagerImpl.java
===================================================================
RCS file: /cvsroot/jpox/JPOX/Core/src/java/org/jpox/resource/PersistenceManagerImpl.java,v
retrieving revision 1.37
diff -u -r1.37 PersistenceManagerImpl.java
--- PersistenceManagerImpl.java 2 Nov 2005 19:15:15 -0000 1.37
+++ PersistenceManagerImpl.java 14 Dec 2005 11:41:25 -0000
@@ -1428,7 +1428,9 @@
*/
public void removeQueryResult(QueryResult queryResult)
{
- mc.removeQueryResult(queryResult);
+ if (mc!=null) {
+ mc.removeQueryResult(queryResult);
+ }
}
/* (non-Javadoc)
Index: ManagedConnectionImpl.java
===================================================================
RCS file: /cvsroot/jpox/JPOX/Core/src/java/org/jpox/resource/ManagedConnectionImpl.java,v
retrieving revision 1.11
diff -u -r1.11 ManagedConnectionImpl.java
--- ManagedConnectionImpl.java 2 Nov 2005 19:15:15 -0000 1.11
+++ ManagedConnectionImpl.java 14 Dec 2005 11:43:27 -0000
@@ -134,6 +134,7 @@
((PersistenceManagerImpl)i.next()).setManagedConnection(null);
}
handles.clear();
+ disconnectQueryCache();
}
/**
Must not commit SQL Connection within running UserTransaction
I imagine this fix could be a problem if ConnectionURL etc. is configured instead of ConnectionFactoryName, as I don't know whether UserTransaction.commit() will commit the SQL Connection when it wasn't obtained via a JCA datasource (which I'd think is the case when using ConnectionURL etc. instead of ConnectionFactory).
However, if the connection was obtained via a JCA datasource, it seems to be the appserver's responsibility to commit it when the UserTransaction is committed.
Index: ManagedTransaction.java
===================================================================
RCS file: /cvsroot/jpox/JPOX/Core/src/java/org/jpox/resource/ManagedTransaction.java,v
retrieving revision 1.17
diff -u -r1.17 ManagedTransaction.java
--- ManagedTransaction.java 13 Dec 2005 11:27:14 -0000 1.17
+++ ManagedTransaction.java 14 Dec 2005 11:56:03 -0000
@@ -341,7 +341,9 @@
sync.beforeCompletion();
}
- conn.commit();
+ // JBoss 4.0.3 SP1 doesn't want us to commit the connection during a managed transaction here.
+ // should it really be our responsibility to commit the SQL connection anyway?!
+ //conn.commit();
success = true;
}
Please tell me what your objections to these patches are, if any. I think it would be great if JPOX would run fine in JBoss 4.0.3 SP1 for everyone.
Regards,
Jörg
--
__________________________________________________________
Dipl.-Inf. Jörg von Frantzius | artnology GmbH
| Milastr. 4
Tel +49 (0)30 4435 099 26 | 10437 Berlin
Fax +49 (0)30 4435 099 99 |
http://www.artnology.com
_______________________________|__________________________