You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by RamAESIS <rs...@hcl.in> on 2009/03/05 10:23:25 UTC

OneToMany lazy loading

Hi,

I am trying to lazy load a child collection in a one-to-many relationship as
shown below:

      @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
      @ElementJoinColumns({
           @ElementJoinColumn(name="ColA",referencedColumnName="ColX"),
           @ElementJoinColumn(name="ColB",referencedColumnName="ColY"),
           @ElementJoinColumn(name="ColC",referencedColumnName="ColZ")

      })
      public Collection<TableB> TableB_Obj = new HashSet<TableB>();

But after accessing the child collection  also it is still NULL, EAGER mode
works properly. Any guess or guidance in this issue is highly appreciated.
Thanks in advance.

Regards,
Ram

-- 
View this message in context: http://n2.nabble.com/OneToMany-lazy-loading-tp2428285p2428285.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: OneToMany lazy loading

Posted by Simone Gianni <si...@apache.org>.
Hi Ram,
looking at your snippet, I see that you declared the field public. Are 
you then trying to access it using parent.TableB_Obj ? Cause in that 
case I don't think OpenJPA is able to catch your call and load the 
collection when needed. Try declaring the field private, creating a 
getter, and using the getter to access it. I use getters and lazy 
loading works correctly.

Hope this helps,

Simone

RamAESIS wrote:
> Hi,
>
> I am trying to lazy load a child collection in a one-to-many relationship as
> shown below:
>
>       @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
>       @ElementJoinColumns({
>            @ElementJoinColumn(name="ColA",referencedColumnName="ColX"),
>            @ElementJoinColumn(name="ColB",referencedColumnName="ColY"),
>            @ElementJoinColumn(name="ColC",referencedColumnName="ColZ")
>
>       })
>       public Collection<TableB> TableB_Obj = new HashSet<TableB>();
>
> But after accessing the child collection  also it is still NULL, EAGER mode
> works properly. Any guess or guidance in this issue is highly appreciated.
> Thanks in advance.
>
> Regards,
> Ram
>
>   


-- 
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
http://www.simonegianni.it/