java - How to create OR blocks containing multiple criterias with Hibernate? -
java - How to create OR blocks containing multiple criterias with Hibernate? -
i have multiple criterias constructed out of criterions , create disjunction between them.
criteria criteria1 = hibernatesession.createcriteria(myclass); criteria1.add(restrictions.eq(field1, value1)); criteria1.add(restrictions.eq(field2, value2)); criteria1.add(restrictions.ne(field3, value3)); which create where field1 = value1 , field2 = value , field3 != value3.
then,
criteria criteria2 = hibernatesession.createcriteria(myclass); criteria2.add(restrictions.eq(field4, value4)); criteria2.add(restrictions.eq(field5, value5)); which create where field4 = value4 , field5 = value5.
my end goal here create disjunction between criteria1 , criteria2 have where (field1 = value1 , field2 = value , field3 != value3) or (field4 = value4 , field5 = value5).
i know disjunction / conjonction in hibernate, however, take criterions (and not criterias).
have of achieved similar before ?
create 2 , criterions. add together them criteria or.
criteria criteria = hibernatesession.createcriteria(myclass); criterion rest1= restrictions.and(restrictions.eq(field1, value1), restrictions.eq(field2, value2), restrictions.ne(field3, value3)); criterion rest2= restrictions.and(restrictions.eq(field4, value4), restrictions.eq(field5, value5)); criteria.add(restrictions.or(rest1, rest2)); java hibernate
Comments
Post a Comment