openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daryl Stultz <da...@6degrees.com>
Subject SingleFieldManager crash
Date Tue, 15 Sep 2009 18:14:37 GMT
I had this exception again:
<openjpa-1.2.1-r752877:753278 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException: Encountered unmanaged
object in persistent field "model.MyAEntity.propb" 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: model.MyBEntity-892
        at
org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:754)
        at
org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:594)
        at
org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:562)
        at
org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:478)

This time it happened in my development code rather than production and the
object graph is a bit simpler than my previous problem. Notice that the
FailedObject has an ID of 892, that's the primary key of the database
record, so the object is not "new".

Here is relevant code from SingleFieldManager:

   *private* *void* preFlushPC(ValueMetaData vmd, Object obj, *boolean*logical,

        OpCallbacks call) {

        *if* (obj == *null*)

            *return*;


        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);

        } *else* {

            *if* (vmd.getCascadePersist() == ValueMetaData.*
CASCADE_IMMEDIATE*) {

                *if* (!_broker.isDetachedNew() && _broker.isDetached(obj))

                    *return*; // allow but ignore

            }

            sm = _broker.getStateManager(obj);

            *if* (sm == *null* || !sm.isProvisional()) {

                sm = _broker.persist(obj, *null*, *true*, call);

                // ensure generated IDs get assigned properly

                *if* (!logical)

                    ((StateManagerImpl)sm).assignObjectId(*false*, *true*);

            }
        }

The red line is the one that threw the error. If I repeat the transaction
and step through the debugger it returns on the blue. I.e., every time the
object is determined to be detached (which agrees with my understanding). I
don't know if it fails because sm is null or !sm.isPersistent().

Is is possible my object is losing its state manager? I'm not taking any
steps to serialize anything. I'm using Tomcat with Zk and as far as I know
these technologies are not serializing my objects.

If I set my fields to CascadeType.PERSIST (as the exception suggests) the
majority of the executions should return at the green line (I think). But
some (when this strange condition occurs) may hit the purple line. Since my
object has an ID and is already in the database, I assume this will also
crash.

I'm using build-time enhancement with OpenJPA 1.2.1.

I REALLY need some help understanding this. It's been dogging me for months.
As I expand my use of OpenJPA the problem will certainly manifest itself
more widely.

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