sql hibernate和/或限制

时间:2013-03-25 08:10:33

标签: c# sql hibernate restrictions

我的sql应该是这样的:

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

但是如何用hibernate做“和(x或y)”限制?

1 个答案:

答案 0 :(得分:0)

LogicalExpression

怎么样?

请尝试 AND 条件:

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

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

对于 OR 条件,请使用此

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

 List results = cr.list();