persist()
is well defined. It makes a transient instance persistent. However, it doesn't guarantee that the identifier value will be assigned to the persistent instance immediately, the assignment might happen at flush time. The spec doesn't say that, which is the problem I have withpersist()
.
persist()
also guarantees that it will not execute an INSERT statement if it is called outside of transaction boundaries. This is useful in long-running conversations with an extended Session/persistence context.
A method likepersist()
is required.
save()
does not guarantee the same, it returns an identifier, and if an INSERT has to be executed to get the identifier (e.g. "identity" generator, not "sequence"), this INSERT happens immediately, no matter if you are inside or outside of a transaction. This is not good in a long-running conversation with an extended Session/persistence context.
Sunday, January 13, 2019
What's the advantage of persist() vs save() in Hibernate?
Subscribe to:
Post Comments (Atom)
-
@NotNull CharSequence, Collection, Map or Array object cannot be null, however can be empty. @NotEmpty The CharSequence, Collection...
-
We learned about mapping associated entities in hibernate already in previous tutorials such as one-to-one mapping and one-to-many mappi...
-
FetchType (Lazy/Eager) instructs whether the entity to be loaded eagerly or lazy, when there is a call. FetchMode (Select/Join) instructs...
No comments:
Post a Comment