The field member 'inUnitOfWork_' in org.apache.derby.client.am.Connection is not maintained correctly for XA transactions.
The following code does not throw any exception for client and embedded drivers (but it should throw):
xaResource = xaConnection.getXAResource();
While if we execute some queries in unit of work and will try to close the connection afterwards, the close will fail even if the transaction would be disassociated from the connection (calling XAResource.end). It should be allowed to close the connection if there is no transaction associated.
If the exception is thrown client driver throws exception:
java.sql.SQLException: Cannot close a connection while a transaction is still active.
while embedded driver throws
java.sql.SQLException: Invalid transaction state.
I would say that the exception thrown should be the same. I'll would prefer the first one since it explaines better what is going on.