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: Get @Id field value (FK) without loading entity (JOIN) when using FetchGroups or Lazy Loading
Date Tue, 25 Nov 2008 00:51:13 GMT
Ideally, simply navigating to a related field and getting the id of  
that field should not trigger loading behavior, should it?

After all, you don't know exactly what fields to load until the user  
actually wants a field that isn't loaded. The field that triggers the  
database operation should influence what kind of fetch is done by the  
database. It sounds like this behavior should work: for non-relation  
fields, the current fetch plan is applied to the field’s owning  
instance, and the fields in the field’s load-fetch-group, plus the  
field itself are added to the list of fields.


On Nov 24, 2008, at 3:53 PM, Pinaki Poddar wrote:

> Hi,
>  Sorry for delayed response.
>  Let me restate the problem to see if I understand it correctly
>  1. Entity A has a one-to-one, lazily fetched relation to Entity B.
>     public class A {
>      @OneToOne(fetch=LAZY)
>       private B b;
>  2. You want to get an instance of A in memory, but not the related
> instance of B. Nor you want a join between Table for A and Table for  
> B.
>  3. But you should be able to access the primary field of B because  
> OpenJPA
> has fetched the value but hidden it somewhere.
>  I have attached a sketch of how this can be done in three attached  
> file,
> hopefully they are self-explanatory :)
>  The short answer is you need to get hold of OpenJPAStateManager for  
> A --
> the proxy object that intercepts and manages the persistent state of
> original A. That StateManager has the primary key of B which saves  
> OpenJPA
> another join in case the user later calls A.getB().
> -- 
> View this message in context:
> Sent from the OpenJPA Users mailing list archive at

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

View raw message