1

Well when I read about different between hibernate 'Persist' and 'Save' method, Many articles has notably highlighted that "Save method can execute outside the transaction boundary"
This statement made me really confused and I read fair enough articles to understand the real meaning of this, but no luck !!! now I have following points to clarify.

Question 1

is this true?? If true then

Question 2

[assuming transaction means physical DB transaction]

As far as I know no database execution can happen with out transaction, then what it mean by outside of transaction boundary?

Question 3

[assuming transaction means logical transaction]

According materials I refereed, 'session' lay out the logical transaction. so even if it use persist() or save() to persist data it will flush and commit to only after when explicitly commit or session.flush or closing the session.

since session is the logical transaction and no execution can be perform without a session, then what is it mean by save() work outside transaction?

If someone can give me a clear detailed answer it would be a great help Thanks a lot !!!

shanika yrs
  • 303
  • 1
  • 13
  • @BillyFrost thanks ! I removed the tag – shanika yrs May 30 '18 at 10:47
  • The javadoc certainly doesn't talk anything about that. It specifies the only difference as `save()` generating, assigning and returning the identifier. – Kayaman May 30 '18 at 10:48
  • Duplicate of https://stackoverflow.com/questions/5862680/whats-the-advantage-of-persist-vs-save-in-hibernate? – ewramner May 30 '18 at 10:49
  • @ewramner , yes I have seen that thread, my this question arise only after reading the accepted answer in that thread. That is why I created this thread with specific details. So I don't think this is duplicate. Thanks! – shanika yrs May 30 '18 at 10:52

1 Answers1

2

This is a good article that is too long to copy: https://www.journaldev.com/3481/hibernate-session-merge-vs-update-save-saveorupdate-persist-example. In essence:

Q1: Yes, it is true. It means you can call session.save(object) without first having done session.beginTransaction(). You must still have an open session.

Q2: Transaction means Hibernate's transaction, presumably the session will still use a transaction towards the database but a very short one and perhaps implicit (auto-commit).

Q3: It means outside of a Hibernate transaction started by beginTransaction.

ewramner
  • 5,810
  • 2
  • 17
  • 33