Hi Daryl, You aren't alone, the DetachedStateField is not the most intuitive function (IMHO), and maybe I didn't explain it perfectly in the email you found.
There are two parts to the DetachState property that are of interest. The first one "fgs" controls which fields will be available after OpenJPA detaches an entity, and later it affect the assumptions we make when the entity is re-attached. The second part (DetachedStateField=true) affects what happens when the entity is serialized. The first part has three values : all, loaded and fetch-groups. With "fgs" being an alias for fetch-groups. All indicates that all fields will be loaded before detaching. Loaded indicates that only the fields that have already been loaded will be available. Fetch-groups indicates that anything in the current fetch group will be available. Chances are that you haven't specified a fetch group so fetch-groups isn't terribly interesting in your environment. The second part also has three values: true, false, and transient. True indicates that a serializable (and potentially large) detached StateManager will be stored in the entity instance. False indicates that no detached SstateManager will be used. Transient indicates that a transient one will be used (usefull if you stay on the same JVM). It's the StateManager that stores which fields have been loaded or modified by the application. Note that this setting (in particular the second one) need to be be present when you enhance your entities - so you might have to run the PCEnhancer tool or ant task to get the desired behavior. So one way to fix the problem for you is to use "all". This forces all fields to be loaded prior to detachment (could be DB intensive) but guarantees that any changes you make to the detached entity are tracked. <property name="openjpa.DetachState" value="all(DetachedStateField=true)" /> Another approach is to use "loaded" and call the appropriate accessor methods for the members you are interested in. <property name="openjpa.DetachState" value="loaded(DetachedStateField=true)" /> The OpenJPA manual covers this topic as well and might explain it better than I can at [1]. [1] http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_detach_behavior Hope this helps, -mike On Tue, Jun 23, 2009 at 7:59 PM, Daryl Stultz <[email protected]> wrote: > Hello, > > I discovered that a property on a detached entity set to null was not > having > the null value persisted following a merge. I found this thread > http://osdir.com/ml/apache.openjpa.user/2008-03/msg00045.html > and put > <property name="openjpa.DetachState" value="fgs(DetachedStateField=true)" > /> > into persistence.xml > > This took care of the problem. My entity has child entities set to > CascadeType.ALL but now merging the parent does not merge the children. I'm > going crazy with this! What's the right way to save an entity with newly > nulled values without breaking cascade? > > Thanks. > > -- > Daryl Stultz > _____________________________________ > 6 Degrees Software and Consulting, Inc. > http://www.6degrees.com > mailto:[email protected] >
