-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate FetchMode.JOIN for Lazy loaded Lists
PostPosted: Thu Nov 10, 2016 9:00 pm 
Newbie

Joined: Tue Nov 08, 2016 1:54 am
Posts: 14
I have defined an entity like;


Code:
@Entity
@Table(name = "questionask", uniqueConstraints = @UniqueConstraint(columnNames = "code"))
public class QuestionAsk {

   
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "questionAsk")
   private List<Answer> answerList = new ArrayList<Answer>(0);

...

}


Here answerList is defined as FetchType.LAZY. To fetch answerList, when I require, at the backend I do like;

Code:
criteria.setFetchMode("answerList", FetchMode.JOIN);


But it is not returning the answerList to the client.

Code:
List<QuestionAsk> resultList = QuestionAskService.get(filter);


The resultList contains answerList, but when I send response to client like;
Code:
Response.ok(resultList).build();


AnswerList is not coming with the QuestionAsk entity. That is, it shows empty array. How can I overcome this?


Top
 Profile  
 
 Post subject: Re: Hibernate FetchMode.JOIN for Lazy loaded Lists
PostPosted: Fri Nov 11, 2016 3:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
How does the SQL query looks like?

You need to enable SQL logging. Check out this article for more info.


Top
 Profile  
 
 Post subject: Re: Hibernate FetchMode.JOIN for Lazy loaded Lists
PostPosted: Sun Nov 13, 2016 9:50 pm 
Newbie

Joined: Tue Nov 08, 2016 1:54 am
Posts: 14
It is a big paragraph;
Here it is;
Quote:
12:48:38,443 INFO [stdout] (default task-30) Hibernate: select this_.id as id1_55_2_, this_.created as created2_55_2_, this_.updated as updated3_55_2_, this_.close_date as close_da4_55_2_, this_.customer2_id as custome21_55_2_, this_.customer_id as customer5_55_2_, this_.open_date as open_dat6_55_2_, this_.suspension_off_date as suspensi7_55_2_, this_.suspension_on_date as suspensi8_55_2_, this_.version as version9_55_2_, this_.visible as visible10_55_2_, this_.ANSWERTYPE2_ID as ANSWERT22_55_2_, this_.ANSWERTYPE_ID as ANSWERT11_55_2_, this_.ASKED as ASKED12_55_2_, this_.code as code13_55_2_, this_.expired as expired14_55_2_, this_.expirySeconds as expiryS15_55_2_, this_.priority as priorit16_55_2_, this_.bpm_process_instance_id as bpm_pro17_55_2_, this_.question2_id as questio23_55_2_, this_.question_id as questio18_55_2_, this_.questionText as questio19_55_2_, this_.recipient2_id as recipie24_55_2_, this_.recipient_id as recipie20_55_2_, 10x1_.id as id1_6_0_, 10x1_.created as created2_6_0_, 10x1_.updated as updated3_6_0_, 10x1_.action as action4_6_0_, 10x1_.code as code5_6_0_, 10x1_.comment as comment6_6_0_, 10x1_.person2_id as person10_6_0_, 10x1_.person_id as person_i7_6_0_, 10x1_.questionask2_id as questio11_6_0_, 10x1_.questionask_id as question8_6_0_, 10x1_.snoozedate as snoozeda9_6_0_, person4_.id as id1_15_1_, person4_1_.created as created2_15_1_, person4_1_.updated as updated3_15_1_, person4_1_.abn as abn4_15_1_, person4_1_.code as code5_15_1_, person4_1_.email2_id as email10_15_1_, person4_1_.imageurl as imageurl6_15_1_, person4_1_.name as name7_15_1_, person4_1_.parent2_id as parent11_15_1_, person4_1_.parent_id as parent_i8_15_1_, person4_1_.zone_id as zone_id9_15_1_, person4_.firstname as firstnam1_45_1_, person4_.latitude as latitude2_45_1_, person4_.longitude as longitud3_45_1_, person4_.jobtitle as jobtitle4_45_1_, person4_.keycloak_id as keycloak5_45_1_, person4_.lastname as lastname6_45_1_ from questionask this_ inner join answer 10x1_ on this_.id=10x1_.questionask2_id left outer join person person4_ on 10x1_.person2_id=person4_.id left outer join crm person4_1_ on person4_.id=person4_1_.id where 10x1_.code in (?) limit ?
12:48:38,504 INFO [stdout] (default task-30) Hibernate: select contexts0_.qa_id as qa_id9_14_0_, contexts0_.id as id1_14_0_, contexts0_.id as id1_14_1_, contexts0_.created as created2_14_1_, contexts0_.updated as updated3_14_1_, contexts0_.className as classNam4_14_1_, contexts0_.entityCode as entityCo5_14_1_, contexts0_.entityId as entityId6_14_1_, contexts0_.entityName as entityNa7_14_1_, contexts0_.reference as referenc8_14_1_ from context contexts0_ where contexts0_.qa_id=?



vlad wrote:
How does the SQL query looks like?

You need to enable SQL logging. Check out this article for more info.


Top
 Profile  
 
 Post subject: Re: Hibernate FetchMode.JOIN for Lazy loaded Lists
PostPosted: Mon Nov 14, 2016 1:27 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
If you run the SQL query in the database console using the same parameters, do you still get an empty result?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.