On Wed, Jul 1, 2009 at 2:11 PM, Michael Dick <[email protected]>wrote:
> Hi Daryl, > > Here's what I've run and I think it does what you're trying to do. Thanks for working on this Mike. Your example is good - it's interesting that it can be sent to the database just by begin/commit as you've shown. You didn't do quite what I want do. Here's what I want: MyEntity entity = em.find(MyEntity.class, entityId); entity.setProperty(20); assertEquals(6, getValueFromDb(entityId)); // default is 6 assertTrue(em.contains(entity)); // after save, it's the same entity.save(); assertEquals(20, getValueFromDb(entityId)); assertTrue(em.contains(entity)); // simulate new web transaction (Force detach) em = getEntityManagerForNewWebTransaction(); assertFalse(em.contains(entity)); entity.setProperty(30); entity.save(); assertFalse(em.contains(entity)); // entity is not the merged instance assertEquals(30, getValueFromDb(entityId)); This actually works, to my surprise. Trying to make it look like your example, I eliminated some problem code. Here's a version that fails on the last line: MyEntity entity = em.find(MyEntity.class, entityId); entity.setProperty(20); // setting this does not automatically update DB assertEquals(6, getValueFromDb(entityId)); // default is 6 // after save, it's the same entity.save(); assertEquals(20, getValueFromDb(entityId)); *entity.setProperty(30);* // simulate new web transaction em = getEntityManagerForNewWebTransaction(); entity.save(); // does not write new value assertEquals(30, getValueFromDb(entityId)); // FAILS!!! I don't know yet if the above test represents the problem my application is having, but the difference is that the property was set while the entity was still attached to the old em. Is that expected behavior? If I move the bold line after em is replaced, it works. -- Daryl Stultz _____________________________________ 6 Degrees Software and Consulting, Inc. http://www.6degrees.com mailto:[email protected]
