We have a scenario where we have to write Bean Managed Stateless Session EJB. We have noticed that, if we get the DB Connection from Connection pool after usertran.begin(), then if there is any error proper rollback is done after issuing usertran.rollback(). But if we get the connection before usertran.begin() statement, rollback is not happening as expected.
For some reasons we need to have the connection created before the Transaction begins. Is there any workaround for this ? Why the system is behaving like this?
We use App. Server - WLS 8.1 DB server - Sybase 12.5 JDBC Driver - weblogic.jdbc.sybase.SybaseDriver
So from your spec, i could understood that you need two types of connection. They are, one should be participate in a transaction and another one shouldn't not be participate in transcation. Am i right?.
For that why you don't go for two types of connection. Before transaction begins and after transaction.begin().Because EJB spec for Transaction says that when you specify transaction.begin() then only the container enlist connection which are managed by container for transaction.
It is true that it does sometimes matter when you get the connection. I don't know all the circumstances, but I do know that distributed transactions using non-XA drivers must start before the connection is obtained, otherwise it doesn't matter if using an XA driver.
I'd say that you should always obtain your connection after you start a JTA transaction. If you can't, then your design is not good. I suspect that your Connection variable is not local: if so, always make it local or you will lay yourself open to problems.
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
subject: opening a DB Connection after Usertran.begin() stmt