|
[
Permalink
| « Hide
]
Christian Bauer added a comment - 14/Dec/05 04:42 PM
Btw, I'm almost done now describing Session and EM APIs and I think we did an excellent job aligning both. However, persist() is really something that stands out as an exception.
Nope, persist() need not immediately assign the identifier - this might be done at flush time. No, there is also no reason why the method should not be void. No, the JPA spec won't be changed. No we should not remove it from the session API.
Explain how the spec can guarantee "a persistent instance has an assigned identifier" if it is assigned only at flush time.
In case anybody finds this thread...
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 with persist(). 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 like persist() 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. |
|||||||||||||||||||||||||||||||||||||||||||||