openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Re: Can I reuse instances?
Date Sun, 08 Apr 2007 17:20:58 GMT
Hi Dain,

On Apr 8, 2007, at 12:17 AM, Dain Sundstrom wrote:

> 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

Do you have some reason to believe this? Entities are cheap. They're  
not like CMP beans that are so expensive they need to be pooled.

Creating Entities from their second level cached versions (em.find)  
should be cheaper than merging because merging requires iterating the  
detached Entity and populating the transaction context Entity.  
Getting an Entity from the second level cache is extremely efficient.

> , and no I can not redesign the system.

Which system are you referring to? If you're using Entities as the  
backing persistent objects for CMP beans, there are lots of different  

> 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

Craig Russell
Architect, Sun Java Enterprise System
408 276-5638
P.S. A good JDO? O, Gasp!

View raw message