Forums Register Login

find and persist in the same trans.

+Pie Number of slices to send: Send
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
We don't have time to be charming! Quick, read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1131 times.
Similar Threads
Java Beat Question
Passed SCBCD 5.0 :)
Entity manager contains() method
SCBCD 5.0 question about merging a removed entity
Persit method strange behaviour
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:25:31.