我的sql应该是这样的:
select cell1 from table
where cell2 = 1
and (cell3 = '' or cell3 is null)
但是如何用hibernate做“和(x或y)”限制?
答案 0 :(得分:0)
请尝试 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();