File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

opening a DB Connection after Usertran.begin() stmt

 
Karthik Prabu
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

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

Thanks
Karthik
 
KasiMurugan Ramasamy
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

I hope you will get me.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic