What is difference between Save() and Persist() method
To answer this question
required attention as both method act like similar, but
there are some basic
difference . which is discussed below
Save
Method: --
- will return the id/identifier when the
object is saved to the database.
- will also save when the object is tried
to do the same by opening a new session after it is detached.
- save() method returns an identifier so
that an insert query is executed immediately to get the identifier, no
matter if it are inside or outside of a transaction.
- Save()
method does not through any
exception even it call detached
transaction state .
Persist
Method -----
- will return void when the object is
saved to the database.
- will throw PersistentObjectException
when tried to save the detached object through a new session.
3. The persist method is called outside of transaction
boundaries, it is useful in long-running conversations with an extended Session
context. On the other hand save method is not good in a long-running
conversation with an extended Session context.
4. The persist () method
doesn’t guarantee that the identifier value will be assigned to the persistent
state immediately, the assignment might happen at flush time.
What is difference between Save() and Persist() method
Reviewed by Mukesh Jha
on
2:15 AM
Rating:
No comments:
Add your comment