-->
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: How to add disjunction to the sql restriction with OR cond
PostPosted: Thu Oct 10, 2013 2:30 pm 
Newbie

Joined: Thu Oct 10, 2013 2:16 pm
Posts: 1
I need to achieve a query like this below.

select * from example where ( a ) or ( b or c or d)

Here a,b,c,d are expressions.

Criteria criteria = session.createCriteria(Example.class);
criteria.add(Restrictions.sqlRestriction("where (a)"));

This is the criteria what i get, which i can't change.
(b or c or d) this can achieved using disjunction.

Disjunction disjunction = Restrictions.disjunction();
disjunction.add(b).add(c).add(d).

But if i add this disjunction to the criteria , it adds AND. i,e select * from example where ( a ) and ( b or c or d). which is not my requirement
criteria.add(disjunction);

Could you please help me on how to add disjunction to sql restriciton with OR condition?


Top
 Profile  
 
 Post subject: Re: How to add disjunction to the sql restriction with OR cond
PostPosted: Fri Oct 11, 2013 1:33 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
Try

Disjunction disjunction = Restrictions.disjunction();
disjunction.add(b).add(c).add(d)
criteria.add(Restrictions.or(
Restrictions.sqlRestriction(a),
disjunction
));


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.