aspose file tools*
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
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.