openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dain Sundstrom <d...@iq80.com>
Subject Can I reuse instances?
Date Sun, 08 Apr 2007 07:17:51 GMT
Is it possible to reuse instances from transaction to transaction?

I would like to be able to create a bean in one transaction, detach  
it and reattach the same instance in a new transaction.  My goal here  
is specifically to reuse instances across transactions because they  
have a very expensive creation cost, and no I can not redesign the  
system.

I tried a quick test case using merge, but merge returned a new  
instance:

         beginTx();
         Employee dain = entityManager.find(Employee.class, dainPk);
         assertEquals(dain.getFirstName(), "Dain");
         commitTx();

         beginTx();
         assertSame(dain, entityManager.merge(dain));
         assertEquals(david.getFirstName(), "Dain");
         commitTx();

When I try to use the refresh method, OpenJPA complains that the  
entity "is not managed by this context".

So is there anyway for me to reuse instances?

-dain

Mime
View raw message