History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: HHH-1273
Type: Improvement Improvement
Status: Closed Closed
Resolution: Rejected
Priority: Major Major
Assignee: Unassigned
Reporter: Christian Bauer
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Hibernate3

Remove persist() on Session API

Created: 14/Dec/05 04:38 PM   Updated: 12/Oct/06 08:04 AM
Component/s: core, documentation
Affects Version/s: None
Fix Version/s: None

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown


 Description  « Hide
This is from a user/documentatio perspective, completely ignoring any reason on the implementation side. Stay with me.

The persist() operation on Session is not cascaded at flush time. This is somewhat unexpected from a users point of view and very difficult to explain and understand (you need excellent knowledge of flushing and cascading). Reason #1 for removal.

The persist() operation in general does not return a database identifier. This is surprising, as the JPA spec clearly requires a persistent instance to have a database identifier value. Since persist() makes instances persistent, it has to have the same semantics for assigning identifiers as save(). Hence, I expect that once this mismatch is resolved in the expert group, the persist() method will return a database identifier. Everything else doesn't make much sense, given the current specification and documentation. Conclusion is that persist() will have the same signature as save(). Reason #2 for removal.

To document persist() properly I need a reason for its existence. Right now I'm telling readers/users to ignore it on the Session API, because it only complicates the situation with no benefit.


 All   Comments   Work Log   Change History   FishEye      Sort Order:
Christian Bauer - [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.

Gavin King - [15/Dec/05 02:44 AM ]
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.

Christian Bauer - [15/Dec/05 03:52 AM ]
Explain how the spec can guarantee "a persistent instance has an assigned identifier" if it is assigned only at flush time.

Christian Bauer - [12/Oct/06 08:04 AM ]
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.