On Mon, Jan 4, 2010 at 4:52 PM, Pinaki Poddar <[email protected]> wrote:

Pinaki, I've presented evidence from several lines that may be confusing the
matter.

>
> As the trace suggests
> > B:2436.isDetached() = false
> > B:2436.getDetachedState() = null
>
> OpenJPA sees neither a detached state nor a version field -- determines B
> to
> be new -- tries to enforce that B has no primary key value because it is
> instructed by @GeneratedValue to auto-generate the primary key -- but B
> does
> have a non-default primary key value -- and results into a long stack
> trace.
>

The above trace segment is from my unittest that produces the "encountered
unmanaged object" error. It is not from the case that produces the
non-default primary key error. I understand you are just giving me a lot of
background so it probably doesn't matter, I just don't want you trying to
"piece together" the evidence when the pieces are not from the same puzzle.


>
> So the process/mechanics (SOAP, deserialization whatever) that has
> instantiated B-2436 has to aid OpenJPA by either retaining its detach state
> field marker or a non-default version field value.


It sounds like a version field may help, and I intend to add one someday,
but I would prefer to figure out why this is happening. Maybe it's a bug in
OpenJPA that could be fixed or something about my coding style that could be
better.


> Otherwise OpenJPA has no
> way to determine that B-2436 is actually a detached instance.
>
> I would think that this would fail, but it works. Can you explain why?

EntityA a = new EntityA();
EntityB b = new EntityB();
b.setId(123); // EntityB with id 123 exists in db, but clearly b is not
managed or detached
a.setB(b);
em.persist(a);


> However, there is another option which does not require serialization
> signature change -- used @DeatchedState annotation on a non-persistent
> Object field in your domain classes.
>
> The docs state:
>
> The OpenJPA enhancer may add a synthetic field to detachable classes to
> hold detached state.

It "may"? Does that mean it will if it needs to? I decompiled an entity
class and it contains these 2 lines:

protected transient StateManager pcStateManager;
private transient Object pcDetachedState;

So it doesn't look to me like adding @DetachedState will change anything.

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

Reply via email to