-->
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.  [ 1 post ] 
Author Message
 Post subject: Union select in query ignored?
PostPosted: Tue Sep 11, 2007 6:44 pm 
Newbie

Joined: Tue Jun 12, 2007 11:16 am
Posts: 5
[using hibernate 3.2, mysql 5]

I'm trying to use a union select in a query to avoid some index penalties that crop up when using an OR statement in the WHERE. (ie. breaking the query into 2 selects allows Mysql to use the correct index for each select instead of using one thats wrong for half of the conditions ) My my case, the conditions on each side of the OR are mirror images of each other (my class is a combination of 2 identical parts... UID0 and UID0Flag0-7 and UID1 and UID1Flag0-7. I'm querying on the UID and flags, but need to search both UID0 and UID1 for my value.

But, it seems like hibernate is throwing away everything after the "UNION SELECT":

Code:
select link from BiLink link where ( link.UID0 = :srcUID and link.UID0Flag1 = true) union select link2 from BiLink link2 where ( link2.UID1 = :srcUID and link2.UID1Flag1 = true)


gets translated into:
Code:
select <snipped_field_list> where hibernateb0_.UID0=? and hibernateb0_.UID0FLAG1=1 limit ?


where its missing the second select with its WHERE UID1=? and UID1FLAG1=1.

BTW, my original query only differed in that there was an "OR" in place of the "union select from where" clause:
Code:
select link from BiLink link where ( link.UID0 = :srcUID and link.UID0Flag1 = true) or ( link2.UID1 = :srcUID and link2.UID1Flag1 = true)


but this wasn't handled well by Mysql 5.

Does Hibernate allow union selects? If so, how do I write it?

-Trevor


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

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.