-->
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: Disjunction is being interpreted as "AND" instead of "OR"
PostPosted: Thu Mar 29, 2012 4:36 pm 
Newbie

Joined: Wed Mar 28, 2012 2:31 pm
Posts: 1
I'll be getting three Lists<Long> and 2 operators op1 , op2 which can be "OR" , "AND", "AND NOT".. i need to form a query like this

for example consider a table employee , i'll be getting three lists List1<long> , list2 , list3 of emp_id's


select emp_num , emp_dpt , emp_name

from employee

where
emp_id in (list1)

op1

emp_id in (list2)

op2

emp_id in (list3)



I have written two methods

public List<Employee> getRequestedEmployee(List<Long> list1 , List<Long> list2 , List<Long> list3 , String op1 , String op2){

DetachedCriteria dc = DetachedCriteria.forClass(Employee)

if(!CollectionUtils.isEmpty(list1)){
dc.add()Restrictions.in(list1,emp_id);
}

if(!CollectionUtils.isEmpty(list3){

dc = getCriteria(dc , list2 , op1);//(getCriteria method that is being called here is written down)

}

if(!CollectionUtils.isEmpty(list3){

dc = getCriteria(dc , list3 , op2);//(getCriteria method that is being called here is written down)

}
}

private DetachedCriteria getCriteria( DetachedCriteria dc , List<long>empIdList, String operator){

if(!CollectionUtils.IsEmpty(empIdList)){

if("and".equals(operator)){

Conjunction andOp = Restrictions.Conjunction();
andOp.add(Restrictions.in(empIdList));
dc.add(andOp);
}

else if("or".equals(operator)){

Disjunction orOp = restrictions.disjunction();
orOp.add(Restrictions.in(empIdList))
dc.add(andOp);
}
else{

dc.add(Restrictions.not(empIdList));

}
return dc;

}



I am facing problem with Disjunction .. When ever am passing OR it is interpreting as AND..

for example if am passing op1 = and , op2 = or it is forming like this

select emp_num , emp_dpt , emp_name

from employee

where
emp_id in (list1)

and

emp_id in (list2)

and

emp_id in (list3)



but what i want is



select emp_num , emp_dpt , emp_name

from employee

where
emp_id in (list1)

and

emp_id in (list2)

or

emp_id in (list3)


where ever am expecting or it is putting as and no matter op1 or op2



Need some help...


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.