openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C N Davies" <>
Subject RE: SingleFieldManager crash
Date Fri, 18 Sep 2009 13:54:25 GMT
Daryl I got a bit closer.

Remember the issue is that the line:

			sm = _broker.getStateManager(obj);

Is returning null. 

I have logging inside the broker but the issue goes deeper, getStateManager
calls into the broker implementation class, and calls this line:

		if (ImplHelper.isManageable(obj)) 

Do you have the rest of your stack trace from your original posting of this



-----Original Message-----
From: Daryl Stultz [] 
Sent: Thursday, 17 September 2009 9:40 PM
Subject: Re: SingleFieldManager crash

On Wed, Sep 16, 2009 at 11:41 PM, C N Davies <> wrote:

> I've put a try catch around my code that is triggering the issue,

I've written the following code to assist my debugging:

private void collectJpaDebug(String name, Object object, StringBuffer sb,
EntityManager em) {
sb.append(name + ": " + object);
try {
if (object != null) {
OpenJPAEntityManager emo = (OpenJPAEntityManager) em;
sb.append(emo.isDetached(object) ? "D" : "d");
sb.append(emo.isDirty(object) ? "X" : "x");
sb.append(emo.isNewlyPersistent(object) ? "N" : "n");
sb.append(emo.isPersistent(object) ? "P" : "p");
sb.append(emo.isRemoved(object) ? "R" : "r");
sb.append(emo.isTransactional(object) ? "T" : "t");
EntityManagerImpl emi = (EntityManagerImpl) em;
final Broker broker = emi.getBroker();
sb.append(" BK:");
sb.append(broker.isDetachedNew() ? "C" : "c");
sb.append(broker.isDirty(object) ? "X" : "x");
sb.append(broker.isNew(object) ? "N" : "n");
sb.append(broker.isPersistent(object) ? "P" : "p");
sb.append(broker.isDeleted(object) ? "R" : "r");
sb.append(broker.isTransactional(object) ? "T" : "t");
OpenJPAStateManager sm = broker.getStateManager(object);
sb.append(" SM:");
if (sm != null) {
sb.append(sm.isDetached() ? "D" : "d");
sb.append(sm.isDirty() ? "X" : "x");
sb.append(sm.isNew() ? "N" : "n");
sb.append(sm.isPersistent() ? "P" : "p");
sb.append(sm.isProvisional() ? "V" : "v");
sb.append(sm.isDeleted() ? "R" : "r");
sb.append(sm.isTransactional() ? "T" : "t");
} else {
} catch (Throwable exc) {

This generates a number of "flags" for the various properties. So for this

EntityManager em = getEm();
A a = em.find(A.class, 1);
// EM:dxnPrt BK:cxnPrt SM:dxnPvrt
em = getEm(); // a different em
// EM:Dxnprt BK:cxnprt SM:null
a = new A();
// EM:dxnprt BK:cxnprt SM:null
// EM:dxnprt BK:cxnprt SM:null

I've added the resulting "flags" after the operations. It seems the only
time an object has a state manager is when it is currently managed. Detached
objects have no sm. I guess I had the "feeling" the state manager was part
of the enhanced object, but it looks like it's in the em. So going back to
the code of SingleFieldManager:

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

        OpCallbacks call) {

        *if* (obj == *null*)


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


        } *else* {

I think it's fair to say that it's failing on sm == null rather than
!sm.isPersistent() since the FailedObject is at least detached and possibly
"unmanaged" altogether (whatever that means). Since my debugging always
returns on the blue line, the question is now why, once in a great while,
does it now think that the object is not detached (read: not formerly
managed by a different em). There's also the possiblility that
_broker.isDetachedNew() is wrong - I don't know what that means yet.

Daryl Stultz
6 Degrees Software and Consulting, Inc.

View raw message