-->
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: Problems with OR parenthesis in HQL
PostPosted: Mon Apr 18, 2011 4:12 am 
Newbie

Joined: Mon Apr 18, 2011 3:04 am
Posts: 1
Hi all
I have 2 date ranges startDate and endDate
I need to write an HQL that covers 4 conditions:
1. The range between startDate and endDate.
2. A range that can start before the startDate and can finish after the endDate.
3. A range that can start before the startDate and finishes in range (between) the startDate and endDate
4. A range that can start after the startDate and earlier than (between) the endDate and finishes after the endDate

The problem that HQL drops the parentheses after the 'or' and 'and'
See query:

from Entity
where myVal in (:myVal)
and
// The range between startDate and endDate.
//equivalent to between
(
startDate>= to_date(:startDate, 'dd/mm/yyyy')
and
endDate <= to_date(:endDate , 'dd/mm/yyyy')
)
Or
// A range that can start before the startDate and can finish after the endDate
(
startDate < to_date(:startDate, 'dd/mm/yyyy')
and
endDate > to_date(:endDate , 'dd/mm/yyyy')

)
Or
// A range that can start before the startDate and finishes in range (between) //the startDate and endDate

(
startDate < to_date(:startDate, 'dd/mm/yyyy')
and

(
endDate > to_date(:startDate , 'dd/mm/yyyy')
and
endDate< to_date(:startDate , 'dd/mm/yyyy')
)
)



Or
// A range that can start after the startDate and earlier than
//(between)the
//endDate //and finishes after the endDate
(
startDate> to_date(:startDate , 'dd/mm/yyyy')
and
startDate< to_date(:endDate , 'dd/mm/yyyy')

)
and
endDate>:endDate
)
)

How can I write the HQL without 'losing ' parentheses?


Top
 Profile  
 
 Post subject: Re: Problems with OR parenthesis in HQL
PostPosted: Mon Apr 18, 2011 4:42 am 
Beginner
Beginner

Joined: Mon Apr 04, 2011 3:31 am
Posts: 41
See HHH-550.


AND has a higher precendence than OR according to the SQL standard and all major databases.

_________________
Thanks
Niki


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.