It's not a secret anymore!*
The moose likes Object Relational Mapping and the fly likes Transaction propagation and Persistence Context synchronization with Oracle Stored Procedures Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Transaction propagation and Persistence Context synchronization with Oracle Stored Procedures" Watch "Transaction propagation and Persistence Context synchronization with Oracle Stored Procedures" New topic
Author

Transaction propagation and Persistence Context synchronization with Oracle Stored Procedures

Jayr Motta
Ranch Hand

Joined: Jul 30, 2010
Posts: 110

Hi,

I've been searching about the possibility of propagate a JTA transaction from Java code to Oracle stored procedures and found nothing really relevant. I'm asking this because a coworker is working with this and told me that it worked for him.

What I'm wondering is a situation where some operation has not been flushed because the transaction is still opened and subsequently a stored procedure is called (this procedure doesn't control it's own transaction), will the stored procedure be able to see the pendent operation in the Persistence Context? In other words, will the Persistence Context synchronize somehow with the transactional memory of the underneath database?

I'm studying for the Oracle JPA exam and such thing is not described in the book I'm reading. However I've read in some websites that I googled and people say that such transaction propagation works because there are a integration between JTA and database transactions in certain JDBC drivers (I just can't imagine how it could work, are the transaction manager aware of database transactions??).

Thanks in advance!

http://stackoverflow.com/questions/9672321/transaction-propagation-and-persistence-context-synchronization-with-oracle-stor


Feel free to ask me anything!
www.BlackBeltFactory.com/ui#!/ref=jmotta, SCJP 6, OCWCD JEE5, OCE EJB JEE6
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Calling a stored procedure is not much different than executing any other SQL statement. It will execute in the current transaction, any database changes you have done in the transaction will be visible to the stored procedure.

With JPA, you can also have un-flushed in-memory changes, in this case you may need to call flush() on your EntityManager to write the changes to the database. Also ensure you use the same entity manager (or its connection) to execute the stored procedure. If you use a different em or JDBC connection it will most likely be in a different transaction context.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Jayr Motta
Ranch Hand

Joined: Jul 30, 2010
Posts: 110

James, thanks for your past answer.

I've one more question that a friend of mine said and I couldn't test it yet, maybe you help me one more time. Once I called flush in order to send the in-memory changes I did to the database, it will be already committed or it will become part of the transaction that the stored procedure joined?

Thanks in advance!
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
flush() does not commit the transaction, it only writes the changes to the database in the active transaction. The changes are not committed until you commit the transaction.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transaction propagation and Persistence Context synchronization with Oracle Stored Procedures