openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Sutter <kwsut...@gmail.com>
Subject Re: SingleFieldManager.preFlushPC
Date Fri, 28 Aug 2009 16:25:40 GMT
Hi Daryl,
An unmanaged object is one that has not been associated with a persistence
context (entity manager).  So, as an example, suppose you have two objects
with a one-to-one relationship (Order and ShippingInstructions).  If you
create both objects, but then only call persist() on one of them, you could
experience the exception you posted below when attempting to flush the
information to the database.  The exception text is indicating that an
unmanaged field (ie. ShippingInstructions) was detected when attempting to
flush the parent object (Order).  As indicated, there are several options
for getting around this situation.  You could remember to call persist on
this new ShippingInstructions object, or you could set the properties to do
the cascade operation to the related fields.

Does that help?
Kevin

On Fri, Aug 28, 2009 at 7:15 AM, Daryl Stultz <daryl@6degrees.com> wrote:

> Hello,
>
> I've tried unsuccessfully to get help from the users' list. Hopefully
> someone here can shed some light.
>
> I'm getting this error:
>
> org.apache.openjpa.persistence.InvalidStateException: Encountered unmanaged
> object in persistent field "blah.model.MyEntity.anotherEntity" during
> flush.
>  However, this field does not allow cascade persist. Set the cascade
> attribute for this field to CascadeType.PERSIST or CascadeType.ALL (JPA
> annotations) or "persist" or "all" (JPA orm.xml), or enable cascade-persist
> globally, or manually persist the related field value prior to flushing.
> You
> cannot flush unmanaged objects or graphs that have persistent associations
> to unmanaged objects.
> FailedObject: blah.model.AnotherEntity-1981
>       at
>
> org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:754)
>       at
>
> org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:594)
>
> SingleFieldManager.preFlushPC looks like this, with the last line throwing
> my exception:
>
>        OpenJPAStateManager sm;
>
>
>        *if* (vmd.getCascadePersist() == ValueMetaData.*CASCADE_NONE*) {
>
>            *if* (!_broker.isDetachedNew() && _broker.isDetached(obj))
>
>                *return*; // allow but ignore
>
>
>            sm = _broker.getStateManager(obj);
>
>            *if* (sm == *null* || !sm.isPersistent())
>
>                *throw* *new* InvalidStateException(
>
>                    *_loc*.get("cant-cascade-persist", vmd))
>
>                    .setFailedObject(obj);
>
>
> I can't reproduce the problem, so I don't know if sm is null or sm is not
> persistent. I have 2 questions that are maybe the same: what condition
> leads
> to sm being null or not persistent and what exactly is an "unmanaged"
> object?
>
> Thanks.
>
> --
> Daryl Stultz
> _____________________________________
> 6 Degrees Software and Consulting, Inc.
> http://www.6degrees.com
> mailto:daryl@6degrees.com
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message