On Fri, Aug 28, 2009 at 1:35 PM, Michael Dick <[email protected]>wrote:

> On Fri, Aug 28, 2009 at 11:40 AM, Daryl Stultz <[email protected]> wrote:
> > Does this mean an object that has *never* been associated with an em, or
> > one
> > that is not *currently* associated? Are you referring only to "new"
> > objects?
> > Is a detached instance "unmanaged"?
> >
>
> Both Entities that have never been associated with an EM and those which
> are
> not  currently associated with an EM are considered unmanaged.
>
> Put another way unmanaged == OpenJPA is not tracking the changes you make
> to
> the entity. So new entities and detached entities are unmanaged.
>
> I thought changes were tracked if the instance has a state manager. Is a
detached entity with a state manager considered unmanaged?

Does this look like it should work or fail:

EntityManager em = getEntityManager();
A a = em.find(A.class, 1);
em.close();
em = getEntityManager();
B b = em.find(B.class, 2);
em.close();
em = getEntityManager();
a.setB(b); // presuming this is a different B value than before
em.merge(a);

The property "b" on "a" is not set to Cascade. How about this:

EntityManager em = getEntityManager();
B b = em.find(B.class, 2);
em.close();
em = getEntityManager();
A a = new A();
a.setB(b);
em.persist(a);

This is the general idea to what I'm doing, though the object graph is a bit
more complicated. I'm still trying to understand what state "b" is expected
to be in if I'm not using CascadeType.PERSIST/MERGE.

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

Reply via email to