Use Update() if the entity is a detached object; i.e. the object is not associated with the session anymore.
That means it one of three things : the object has been loaded from a different session; you have cleared the session; or you have evicted the object from the session.
Update() or Lock() to re-associate the object with the session.
Use Save() if the entity is a transient object; i.e. the object is brand spanking new.
Use SaveOrUpdate() if you don't know if the object is new or not.
In all of the above cases, you may still need to call Flush().
Flush() basically synchronize the session with the database.
In other words, Flush() flushes any pending operation that has not been pushed to the database.
If you use transactions, you almost never need to call flush as it is automatically called on commit.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.