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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -