You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by rgarret <RG...@co.pierce.wa.us> on 2007/10/03 18:35:48 UTC

Lazy loading not working.

Hello,

I am have several fields that are being eagerly loaded when they should not
be. Here's a simple example to illustrate my problem:

public class Test {

  private TestEnumeration testEnum; // TestEnumeration is an enumeration (go
figure)

  private TestBean testBean; // TestObject is just a regular bean

  @ManyToOne( fetch = FetchType.LAZY )
  @Column( name = "test_enumeration_id", nullable = false )
  public TestEnumeration getTestEnum( ) {
    return testEnum;
  }

  @OneToOne( cascade = CascadeType.ALL, fetch = FetchType.LAZY )
  @JoinColumn( name = "test_bean_id", nullable = false, updatable = false )
  @ForeignKey
  public TestBean getTestBean( ) {
    return testBean;
  }

}

I have made certain that neither testBean nor testEnum are in any active
fetch groups and yet they are still eagerly fetched. According to my logs
they are not fetched due to being accessed, rather, they are pulled
immediately as if they were in a fetch group or declared eager. 

I do not have this issue with collections (OneToMany) and if in the above
example I change the annotation on testEnum from
@ManyToOne(fetch=FetchType.LAZY) to @Basic(fetch=FetchType.LAZY) it behaves
properly.

In summation, all of my non-collection joined fields seem get fetched
eagerly despite being defined as lazy and not being in any active fetch
group. 

Am I doing something wrong or is this a bug?

Thanks!
-Reece
  
  




-- 
View this message in context: http://www.nabble.com/Lazy-loading-not-working.-tf4562936.html#a13022684
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: Lazy loading not working.

Posted by rgarret <RG...@co.pierce.wa.us>.
Thanks for all the help, everything is going smoothly now. Like I said, the
latest snapshot took care of the OneToOne relationship and it makes sense
that enums are just basic.

Thanks again!
Reece


Kevin Sutter wrote:
> 
> On 10/4/07, Patrick Linskey <pl...@gmail.com> wrote:
>>
>>
>> I believe that you can leave out the @Basic annotation for enums if
>> you'd prefer, as well.
> 
> 
> That is correct.  @Basic is optional for enums.
> 
> Kevin
> 
> -Patrick
>>
>> On 10/4/07, rgarret <RG...@co.pierce.wa.us> wrote:
>> >
>> > Alex,
>> >
>> > I am enhancing all of my model classes at build time. I found a fixed
>> bug
>> > that pertains to my issue:
>> http://issues.apache.org/jira/browse/OPENJPA-347.
>> > After upgrading to the latest snapshot my OneToOne relationship behaved
>> > properly but the ManyToOne still eagerly fetched. I changed from
>> ManyToOne
>> > to Basic and now everything is working well.
>> >
>> > I'm not sure if declaring the relationship as basic is the right thing
>> to do
>> > as it really is ManyToOne. I have verified that retrieval works
>> properly
>> but
>> > have yet to test persisting.
>> >
>> > Thanks for your help,
>> > Reece
>> >
>> >
>> > AlexD. wrote:
>> > >
>> > > Hallo,
>> > >
>> > > I hope that I'm right: you have to use Enhancement for this option...
>> > >
>> > > see
>> > >
>> http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_enhance
>> > > for details.
>> > >
>> > > Best regards,
>> > > Alex
>> > >
>> >
>> > --
>> > View this message in context:
>> http://www.nabble.com/Lazy-loading-not-working.-tf4562936.html#a13040881
>> > Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>> >
>> >
>>
>>
>> --
>> Patrick Linskey
>> 202 669 5907
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Lazy-loading-not-working.-tf4562936.html#a13047066
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: Lazy loading not working.

Posted by Kevin Sutter <kw...@gmail.com>.
On 10/4/07, Patrick Linskey <pl...@gmail.com> wrote:
>
>
> I believe that you can leave out the @Basic annotation for enums if
> you'd prefer, as well.


That is correct.  @Basic is optional for enums.

Kevin

-Patrick
>
> On 10/4/07, rgarret <RG...@co.pierce.wa.us> wrote:
> >
> > Alex,
> >
> > I am enhancing all of my model classes at build time. I found a fixed
> bug
> > that pertains to my issue:
> http://issues.apache.org/jira/browse/OPENJPA-347.
> > After upgrading to the latest snapshot my OneToOne relationship behaved
> > properly but the ManyToOne still eagerly fetched. I changed from
> ManyToOne
> > to Basic and now everything is working well.
> >
> > I'm not sure if declaring the relationship as basic is the right thing
> to do
> > as it really is ManyToOne. I have verified that retrieval works properly
> but
> > have yet to test persisting.
> >
> > Thanks for your help,
> > Reece
> >
> >
> > AlexD. wrote:
> > >
> > > Hallo,
> > >
> > > I hope that I'm right: you have to use Enhancement for this option...
> > >
> > > see
> > >
> http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_enhance
> > > for details.
> > >
> > > Best regards,
> > > Alex
> > >
> >
> > --
> > View this message in context:
> http://www.nabble.com/Lazy-loading-not-working.-tf4562936.html#a13040881
> > Sent from the OpenJPA Developers mailing list archive at Nabble.com.
> >
> >
>
>
> --
> Patrick Linskey
> 202 669 5907
>

Re: Lazy loading not working.

Posted by Patrick Linskey <pl...@gmail.com>.
Hi,

enum field types should be mapped as @Basic; @ManyToOne is for a
back-pointer on a one-to-many relationship (i.e., a collection of
entities). So, it should only be used for persistent types, not simple
types like enums.

I believe that you can leave out the @Basic annotation for enums if
you'd prefer, as well.

-Patrick

On 10/4/07, rgarret <RG...@co.pierce.wa.us> wrote:
>
> Alex,
>
> I am enhancing all of my model classes at build time. I found a fixed bug
> that pertains to my issue: http://issues.apache.org/jira/browse/OPENJPA-347.
> After upgrading to the latest snapshot my OneToOne relationship behaved
> properly but the ManyToOne still eagerly fetched. I changed from ManyToOne
> to Basic and now everything is working well.
>
> I'm not sure if declaring the relationship as basic is the right thing to do
> as it really is ManyToOne. I have verified that retrieval works properly but
> have yet to test persisting.
>
> Thanks for your help,
> Reece
>
>
> AlexD. wrote:
> >
> > Hallo,
> >
> > I hope that I'm right: you have to use Enhancement for this option...
> >
> > see
> > http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_enhance
> > for details.
> >
> > Best regards,
> > Alex
> >
>
> --
> View this message in context: http://www.nabble.com/Lazy-loading-not-working.-tf4562936.html#a13040881
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>
>


-- 
Patrick Linskey
202 669 5907

Re: Lazy loading not working.

Posted by rgarret <RG...@co.pierce.wa.us>.
Alex,

I am enhancing all of my model classes at build time. I found a fixed bug
that pertains to my issue: http://issues.apache.org/jira/browse/OPENJPA-347.
After upgrading to the latest snapshot my OneToOne relationship behaved
properly but the ManyToOne still eagerly fetched. I changed from ManyToOne
to Basic and now everything is working well.  

I'm not sure if declaring the relationship as basic is the right thing to do
as it really is ManyToOne. I have verified that retrieval works properly but
have yet to test persisting.

Thanks for your help,
Reece


AlexD. wrote:
> 
> Hallo,
> 
> I hope that I'm right: you have to use Enhancement for this option...
> 
> see
> http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_enhance
> for details.
> 
> Best regards,
> Alex
> 

-- 
View this message in context: http://www.nabble.com/Lazy-loading-not-working.-tf4562936.html#a13040881
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: Lazy loading not working.

Posted by "AlexD." <al...@btelligent.de>.
Hallo,

I hope that I'm right: you have to use Enhancement for this option...

see
http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_enhance
for details.
-- 
View this message in context: http://www.nabble.com/Lazy-loading-not-working.-tf4562936.html#a13030513
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: Lazy loading not working.

Posted by "AlexD." <al...@btelligent.de>.
Hallo,

I hope that I'm right: you have to use Enhancement for this option...

see
http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_enhance
for details.

Best regards,
Alex
-- 
View this message in context: http://www.nabble.com/Lazy-loading-not-working.-tf4562936.html#a13030513
Sent from the OpenJPA Developers mailing list archive at Nabble.com.