Hi Daryl,
Here's what I've run and I think it does what you're trying to do. FWIW I've
been using 1.2.2-SNAPSHOT for this test and it's passing for me:
@Test
public void testDetachUpdateMergeCommit() {
EntityManager em = emf.createEntityManager();
Person p = em.find(Person.class, 1);
em.close(); // force detach
em = emf.createEntityManager();
assertFalse(em.contains(p));
p.setIntProperty(new Integer(10));
Person p2 = em.merge(p);
assertFalse(em.contains(p));
assertTrue(em.contains(p2));
// No updates have been flushed to the database yet.
assertEquals(2, getPropertyFromDB());
// commit a transaction to write to db.
em.getTransaction().begin();
em.getTransaction().commit();
// after transaction commits the database will have the new value.
assertEquals(10, getPropertyFromDB());
}
-mike
On Wed, Jul 1, 2009 at 11:28 AM, Daryl Stultz <[email protected]> wrote:
> On Wed, Jul 1, 2009 at 12:17 PM, Michael Dick <[email protected]
> >wrote:
>
> > What does myEntity.getEntityManager() return and how is that set into
> your
> > entity (ie is your code managing it, or are getting it from OpenJPA) ?
> >
>
> I'm using a thread local variable. I've written a variation of the unit
> test
> that replaces the save() method with direct factory/em handling and
> em.merge
> calls to eliminate the possibility of bad logic in my save() method as well
> as my thread local handling. It didn't make any difference. I can post the
> other version if you like.
>
>
> --
> Daryl Stultz
> _____________________________________
> 6 Degrees Software and Consulting, Inc.
> http://www.6degrees.com
> mailto:[email protected]
>