0

my sql should look like this:

select cell1 from table
where cell2 = 1
and (cell3 = '' or cell3 is null)

But how to do the "and ( x or y )" restricion with hibernate?

Werner
  • 2,126
  • 2
  • 22
  • 34
  • Possible duplicat http://stackoverflow.com/questions/57484/how-do-you-or-criteria-together-when-using-a-criteria-query-with-hibernate – tostao Mar 25 '13 at 08:22
  • @tostao: Not really. The question you linked is referring to Hibernate's Criteria OR mechanism, while this question refers to Hibernate OR in general (e.g. HQL) – Raul Rene Mar 25 '13 at 08:57

1 Answers1

0

What about LogicalExpression

Try this for AND condition:

Criteria cr = session.createCriteria(table.class);

// To get records matching with AND condistions
LogicalExpression andExp = Restrictions.and(cell2, cell3);
cr.add( andExp );

For OR condition use this

 // To get records matching with OR condistions
  LogicalExpression orExp = Restrictions.or(cell2, cell3);
  cr.add( orExp );

 List results = cr.list();
subodh
  • 6,136
  • 12
  • 51
  • 73