This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft 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 Java 8 in Action this week in the Java 8 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: find and persist in the same trans.
 
Similar Threads
Java Beat Question
SCBCD 5.0 question about merging a removed entity
Passed SCBCD 5.0 :)
Persit method strange behaviour
Entity manager contains() method