SQL hibernate和/或限制

本文关键字:hibernate SQL | 更新日期: 2023-09-27 18:05:33

我的SQL应该是这样的:

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

但是如何在hibernate中执行"and (x或y)"限制呢?

SQL hibernate和/或限制

LogicalExpression

试试AND条件:

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

对于条件使用

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