Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UNCLEAR - Does transaction propogate to JDBC DAO?

 
Joshua White
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,

I find myself working through another departments code. I find a session bean which has a method foo() that participates in a transaction. This method then instantiates a JDBC Data Access Object and calls a method bar(). This method obtains its own connection from the same JNDI DataSource and performs and insert/update and closes its own connection (connection creation and closure occurs within bar, there is no explicit transaction handling code in bar()).

My question, if the larger transaction in foo() gets rolled back for some reason, will the activity in bar() get rolled back also? I have not come across any documentation that indicates either way. I would like to be 100% sure. If you find a resource, please let me know.

I have read through the head first book and it does not mention what happens when and EJB method calls a non EJB class that does JDBC work. Could someone please clarify this for me?

Best Regards,

Joshua
 
Keerthi P
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should work predicatably as you expect. It even works in case where the bar() method is implemented in a 'different' EJB. Also, if the bar() method should update a table in a different database (from different vendor too!), it can achieve consistent rollback by way of distributed transaction (remember two-phase commit?). The EJB container guarantees local as well as distributed transaction.

Though the spec explicitly does not discuss these scenarios, it does mention about local and distributed transaction, which is same as the case above.
 
J. Adam White
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you are saying that even though this DAO (which is not a bean and manages its own connection) will still participate in the same transaction as foo()?

I definitely want to believe this is true, but I need to be sure. If you happen to come across any documentation, please post it here.

Thanks,

Joshua
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is not related to SCBCD, so, it is better to post similar questions at:
http://www.coderanch.com/forums/f-11/EJB-JEE

Nick
 
Keerthi P
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you are saying that even though this DAO (which is not a bean and manages its own connection) will still participate in the same transaction as foo()?


Yes. absolutely, provided all the participating components (EJB, DAO) are running under a J2EE container.

If the DAO is on a remote machine and if EJB makes a plain Java RMI invocation on it, it fails miserably. The transaction simply won't propagate. You need RMI-IIOP to carry transaction and security information across containers.

If you happen to come across any documentation, please post it here.

You best bet will be trying it yourself.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic