openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Re: Lazy load for detached entities
Date Tue, 11 Sep 2007 17:46:18 GMT
Hi Evgeny,

The JPA spec is clear on the concept of a detached instance: the  
instance can be used without access to the underlying database or the  
persistence context whence it came. The instance can be serialized  
and used in a different tier entirely. The instance can be used in a  
completely different persistence context by attaching it to that  
different persistence context. Changes in the detached instance can  
be applied to the database once it is attached to a different  
persistence context.

If you want to continue to access unloaded fields from instances, you  
should not detach them in the first place, and not invalidate (close)  
the entity manager that manages the persistence context.

In my opinion, the TopLink behavior is an aberration.

By the way, the specification is now open for changes, and  
you can give your input if you would like some different standard  


On Sep 11, 2007, at 3:07 AM, Evgeny Shepelyuk wrote:

>> Hi,
>> Lazy loading is not available for detached entities -- by definition,
>> they are no longer associated with the database.
>> You can, however, control whether OpenJPA returns null or throws an
>> exception when an unloaded field is accessed.
>> If you want to be able to lazily access a field after a transaction
>> completes, you might want to consider keeping the entity manager open
>> for the duration of your request.
> The idea is that Toplink JPA supports that feature. OpenJPA - no.
> Maybe this can be done as some configurable behaviour ?
> -- 
> Best Regards
> Evgeny K. Shepelyuk

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

View raw message