-->
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: Multiple queries instead of JOIN
PostPosted: Wed Sep 23, 2009 4:15 pm 
Newbie

Joined: Wed May 27, 2009 1:53 pm
Posts: 2
Hello :)

I am having the following problem:

I have an entity Student that has a ManyToOne relation to an entity City.

When I am executing a query (named or native) fetching all the Students (select student from Student student) Hibernate is executing a SQL query selecting all the Students (let's say I have 200 Students) and then it executes 200 queries selecting the Cities.

Something like:

Code:
select student0_.id as id104_, student0_.email as email104_, student0_.firstname as firstname104_ from STUDENT student0_


and the it executes 200 (the number of Students I have):

Code:
select city0_.id as id96_1_, city0_.name as name96_1_ from CITY city0_ where city0_.id=?


I feels that if it would execute it with a LEFT JOIN it would be more efficient.

I would like any input on that, because it is hugely affecting the performance.


Top
 Profile  
 
 Post subject: Re: Multiple queries instead of JOIN
PostPosted: Wed Oct 07, 2009 4:13 am 
Newbie

Joined: Wed Oct 07, 2009 4:08 am
Posts: 1
Hello

I have the same problem with a manyToOne relation. Did you found a solution?


Top
 Profile  
 
 Post subject: Re: Multiple queries instead of JOIN
PostPosted: Wed Oct 07, 2009 5:50 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
try this code:
Code:
from Student s left join s.city


Top
 Profile  
 
 Post subject: Re: Multiple queries instead of JOIN
PostPosted: Wed Oct 07, 2009 10:09 am 
Newbie

Joined: Wed Sep 30, 2009 2:04 am
Posts: 5
Also you can set batch size for many to one. For example 50 or 100, and hibernate will get students with batches. Not 200 queries.


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.