Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JPA - persisting only when I use EntityTransaction

 
Binu K Idicula
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I tried persistince with both Hibernate and Toplink for a pretty starightforward Entity in my application.


However observed that SaleItem is NOT getting persisted (when I do a select * from SaleItem) unless I uncomment EntityTransaction, xact.begin and xact.commit.
And even if it is not persisted, when I use em.find, it prints properly!

What basic am I missing here?
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must call commit() to have any changes committed to the database. In JPA changes are made to the object model in memory, to have the changes flushed to the database, either flush() or commit() must be called. The find() will find the object in the persistence context, even if it has not been flushed.

 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!