-->
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 generates strange code for "member of" queries
PostPosted: Fri Mar 30, 2012 3:26 pm 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
Hi,

I have a n-to-n association, which is mapped to the database using a link-table: maintable - linktable - attributetable

However, when executing a query to know which main-entry has which attribute which contains memberof ("FROM maintable m where 13 memberof m.collection"), Hibernate generates a really strange and complex query:

Code:
select m.id from maintable s where (13 in (select attributetable.id from linktable l, attributetable a where m.id=l.mainid and l.attributeid=attributetable.id))

Although I've created indices whereever required, Postgresql fails to transform this query into some efficient plan.

Manually I would have written a way simpler query:
Code:
select m.id from maintable m left join linktable l ON (l.mainid=s.id) where l.attributeid=13

Which returns the same results and can be evaluated in next to no time using the index.

Any idea why Hibernate decides to create such a complex query?

Thank you in advance, Clemens


Top
 Profile  
 
 Post subject: Re: Hibernate generates strange code for "member of" queries
PostPosted: Sun Apr 01, 2012 6:52 pm 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
Is there a better place for this question - maybe the mailing lists?

Thanks, Clemens


Top
 Profile  
 
 Post subject: Re: Hibernate generates strange code for "member of" queries
PostPosted: Thu Apr 05, 2012 1:27 pm 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
bump


Top
 Profile  
 
 Post subject: Re: Hibernate generates strange code for "member of" queries
PostPosted: Sun Apr 29, 2012 4:33 pm 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
bump


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.