users@glassfish.java.net

Re: JPA/Toplink? question related to _at_Transient fields

From: <glassfish_at_javadesktop.org>
Date: Thu, 15 May 2008 09:21:51 PDT

Hello,

I'll share what I know, and hopefully it helps clear up some of the questions.

First, merge is different from persist. Persist does take the object passed in and make it managed, where as merge must return a managed instance. The spec explicitely states that merge will make a copy of the detached object to use as the managed object - keeping the object passed in detached. So this precludes providers from simply determining if the object is new and then calling persist on it, but allows consistent behaviour for the case where you don't know if its new or existing. It also makes things less error prone when calling merge on a tree where some objects may exist, and some maybe new. Calling persist on any new object in such a situation would fail, as it may end up referencing unmanaged objects.

I can't recall what the spec states about transient data. But from a practical point, a provider could not reliably copy/merge transient data from detached objects into managed objects. It would be too error prone. At any given time though, your object maybe coming from the cache, or it maybe coming from the database (in which case any transient data would be lost anyway), it wouldn't be safe to rely on transient data being there. Some users have gotten around this by using events such as postload or postmerge to copy or calculate the transient data themselves.

Hope this helps,
Chris
[Message sent by forum member 'chris_delahunt' (chris_delahunt)]

http://forums.java.net/jive/thread.jspa?messageID=274613