• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Transaction propagation and Persistence Context synchronization with Oracle Stored Procedures

 
Ranch Hand
Posts: 110
Google Web Toolkit Java Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 553
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jayr Motta
Ranch Hand
Posts: 110
Google Web Toolkit Java Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic