-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Lazy fetch problem?
PostPosted: Thu Mar 04, 2010 6:57 pm 
Newbie

Joined: Tue Aug 22, 2006 3:32 am
Posts: 17
Hi,
I have mapped file called Seller. It has 2 lazy many to one associations :

Code:
...
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "seller")
   public Set<SellerSchedule> getSellerSchedules() {
      return this.sellerSchedules;
   }

   public void setSellerSchedules(Set<SellerSchedule> sellerSchedules) {
      this.sellerSchedules = sellerSchedules;
   }

   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "seller")
   public Set<AveaCashAuthorizationRequest> getAveaCashAuthorizationRequests() {
      return this.aveaCashAuthorizationRequests;
   }

   public void setAveaCashAuthorizationRequests(
         Set<AveaCashAuthorizationRequest> aveaCashAuthorizationRequests) {
      this.aveaCashAuthorizationRequests = aveaCashAuthorizationRequests;
   }
...


When i try to load seller ("select s from Seller s") it fetches lazy assoc "AveaCashAuthorizationRequests" not other association(SellerSchedules).
Here is the generated sqls:
Code:
Hibernate:
    /* load com.orm.cws.Seller */ select
        seller0_.Id as Id11_1_,
        seller0_.Address as Address11_1_,
        seller0_.BankAccount as BankAcco3_11_1_,
        seller0_.CountyRecordNo as CountyRe4_11_1_,
        seller0_.CreationDate as Creation5_11_1_,
        seller0_.Email as Email11_1_,
        seller0_.Fax as Fax11_1_,
        seller0_.Name as Name11_1_,
        seller0_.Note as Note11_1_,
        seller0_.ObjectVersion as ObjectV10_11_1_,
        seller0_.Password as Password11_1_,
        seller0_.Phone1 as Phone12_11_1_,
        seller0_.Phone2 as Phone13_11_1_,
        seller0_.StatusRecordNo as StatusR18_11_1_,
        seller0_.Stock as Stock11_1_,
        seller0_.TaxNumber as TaxNumber11_1_,
        seller0_.TaxOffice as TaxOffice11_1_,
        seller0_.UserName as UserName11_1_,
        aveacashau1_.SellerId as SellerId3_,
        aveacashau1_.RecordNo as RecordNo3_,
        aveacashau1_.RecordNo as RecordNo22_0_,
        aveacashau1_.MIResRecordNo as MIResRec6_22_0_,
        aveacashau1_.CashAuth as CashAuth22_0_,
        aveacashau1_.RequestId as RequestId22_0_,
        aveacashau1_.RequestTime as RequestT4_22_0_,
        aveacashau1_.SellerId as SellerId22_0_,
        aveacashau1_.Stan as Stan22_0_
    from
        CreditWebService.dbo.Seller seller0_
    left outer join
        CreditWebService.dbo.avea_CashAuthorizationRequest aveacashau1_
            on seller0_.Id=aveacashau1_.SellerId
    where
        seller0_.Id=?


Why it tries to get "lazy" property?
Thanks.


Top
 Profile  
 
 Post subject: Re: Lazy fetch problem?
PostPosted: Fri Mar 05, 2010 4:43 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
xkurt wrote:
I have mapped file called Seller. It has 2 lazy many to one associations :


no. Set<SellerSchedule> is set for EAGER loading (fetch = FetchType.EAGER)



xkurt wrote:
Why it tries to get "lazy" property?


set all properties to FetchType.LAZY

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: Lazy fetch problem?
PostPosted: Fri Mar 05, 2010 6:33 pm 
Newbie

Joined: Tue Aug 22, 2006 3:32 am
Posts: 17
sorry "FetchType.EAGER" must be "FetchType.LAZY" actually, it was copy-paste problem.
I want to attract your attention to converted SQL now, why AveaCashAuthorization is fetching eagerly? It is LAZY?

left outer join
CreditWebService.dbo.avea_CashAuthorizationRequest aveacashau1_
on seller0_.Id=aveacashau1_.SellerId


Top
 Profile  
 
 Post subject: Re: Lazy fetch problem?
PostPosted: Fri Mar 05, 2010 7:35 pm 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
xkurt wrote:
..., why AveaCashAuthorization is fetching eagerly? It is LAZY?

left outer join
CreditWebService.dbo.avea_CashAuthorizationRequest aveacashau1_
on seller0_.Id=aveacashau1_.SellerId


It's is an eager fetching. I suspect this comes round due combination with the mappedBy attribute (inverse relation). I'm not expert in Hibernate but I have no issue with lazy fetching when I use FetchType.LAZY with collections (I'm not using mappedBy attribute)

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: Lazy fetch problem?
PostPosted: Sat Mar 06, 2010 7:56 pm 
Newbie

Joined: Tue Aug 22, 2006 3:32 am
Posts: 17
removing "mappedBy" property did not solve my problem. It caused new problems, sql grammar exceptions...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.