-->
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.  [ 2 posts ] 
Author Message
 Post subject: setMaxResults and fetch="subselect"
PostPosted: Thu Jan 08, 2009 4:51 pm 
Senior
Senior

Joined: Thu Jan 08, 2009 3:48 pm
Posts: 168
I came across this while trying out some optimization strategies for Hibernate, version used is 3.2.6GA

Code:
Query query = session.createQuery("from User u");
query.setMaxResults(1000);
ArrayList<User> users = (ArrayList<User>) query.list();
for (User user : users) {
    String s = user.getProducts().iterator().next().getName();
}


user->products is mapped with fetch="subselect":
Code:
<set name="products" table="USER_PRODUCTS" cascade="all" fetch="subselect">
<key column="user_id" />
<many-to-many column="product_Id" class="data.Product"/>
</set>

The resulting queries are:
Quote:
Hibernate:
select
user0_.ID as ID0_,
user0_.username as username0_,
user0_.password as password0_,
user0_.title as title0_,
user0_.firstname as firstname0_,
user0_.lastname as lastname0_,
user0_.email as email0_,
user0_.account_id as account8_0_
from
USERS user0_ limit ?

Hibernate:
select
products0_.user_id as user1_1_,
products0_.product_Id as product2_1_,
product1_.ID as ID3_0_,
product1_.name as name3_0_,
product1_.price as price3_0_
from
USER_PRODUCTS products0_
left outer join
PRODUCTS product1_
on products0_.product_Id=product1_.ID
where
products0_.user_id in (
select
user0_.ID
from
USERS user0_
)


So the setMaxResults affected the query on users, but not the subselect to get the products.

FAQ, documentation and forum search turned up nothing that helped.
The only reference i found of this is http://opensource.atlassian.com/projects/hibernate/browse/HHH-304

Is this behaviour known and accepted or did i miss something?

any feedback appreciated

Patrik


Top
 Profile  
 
 Post subject: Re: setMaxResults and fetch="subselect"
PostPosted: Wed Aug 10, 2011 1:07 pm 
Newbie

Joined: Thu Jul 15, 2010 6:44 am
Posts: 13
Hi Patrik,

Have your found out a solution to the same ?

We have been hit by the same road block, the subselect fetch strategy resolves the N+1 select to a large extent.

I have placed a comment on the JIRA raised by Gavin King too, with this issue in place, the feature of subselect is null and void, of little use.

If you have not already, would request you to vote for this fix on the JIRA.


Vikram.


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