我的 sql 应该是这样的:
select cell1 from table
where cell2 = 1
and (cell3 = '' or cell3 is null)
但是如何用hibernate做“and(x or y)”限制呢?
我的 sql 应该是这样的:
select cell1 from table
where cell2 = 1
and (cell3 = '' or cell3 is null)
但是如何用hibernate做“and(x or y)”限制呢?
逻辑表达式怎么样
试试这个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();