• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

find and persist in the same trans.

Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ?

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic