I've just deployed by first OpenJPA to a live production system. I'm getting
an occasional error:

InvalidStateException: Encountered unmanaged object in persistent field
> "blah.MyEntity.addedBy" 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.
>

I have MyEntity with a User entity as the "addedBy" field. It is true that
addedBy is not set to cascade. What I am doing is instantiating a new
MyEntity instance and retrieving the "editing user" using em.find(...). Upon
save (in a different em), I set myEntity.addedBy to the editing user (and
persist). The editing user must be managed as it came from em.find(...). No
changes to the editing user instance are made, it is merely for setting the
addedBy field. Some 80 transactions have been made with 2 failures like
above.

What could make OpenJPA interpret the editing user instance as unmanaged or
what could make it become unmanaged?

Thanks.

-- 
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:[email protected]

Reply via email to