views:

27

answers:

1

I have some legacy JDBC code that is used within an EJB, in this code a call to setAutocommit() is made (which is not allowed for managed transactions, for understandable reasons).

I would like to skip this method call if the code is used within a managed transaction, but let the call remain if used in an un-managed context.

Is there a standardised way to detect if a JDBC Connection object is "managed" or not?

+2  A: 

A bit decent transaction manager does setAutoCommit(false) and setTransactionIsolation(Connection.TRANSACTION_XXX).

Depending on the JDBC driver and the transaction manager used, you may have some luck with getAutoCommit() and/or getTransactionIsolation(). Determine by testing which values are been used in both cases so that you can learn how to distinguish the one from other.

BalusC
Good advice! I eventually decided to just skip the setAutoCommit entirely though, since I realized the code I had would really just be used within a container at the moment anyway, and will hopefully be completely deprecated soon, but your suggestions seems like a good solution would I need to do it.
Brummo