This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes find and persist in the same trans. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "find and persist in the same trans." Watch "find and persist in the same trans." New topic
Author

find and persist in the same trans.

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi

I spotted the next behavior : if you use find (or getReference) method before the persist in the same transaction the the managed entity added with persist is not stored in the database. I really don't understand why ?

Take a look on the next code snippet :


I expect that this snippet synchronize the actual persistence context with the database when the transaction ends, it does not. The only chance to get the MyEntity persisted is to call flush.
More, if I remove the getReference issue then the MyEntity is persisted when the transaction ends and this without to call flush - by hand.
This behavior confuse my because differ from the one described in every JEE book (the persistence context is synchronized with the database when the transaction ends or a compl. query will run).
I encounter the same behavior with find method.

What you guys think about ? Why is this happen ?

regards,
Mihai


SCJP, SCJD, SCWCD, OCPJBCD
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: find and persist in the same trans.
 
Similar Threads
Persit method strange behaviour
SCBCD 5.0 question about merging a removed entity
Java Beat Question
Passed SCBCD 5.0 :)
Entity manager contains() method