【问题标题】:sql hibernate and or restrictionssql休眠和或限制
【发布时间】:2013-03-14 15:58:33
【问题描述】:

我的 sql 应该是这样的:

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

但是如何用hibernate做“and (x or y)”限制呢?

【问题讨论】:

  • @tostao:不是真的。您链接的问题是指 Hibernate 的 Criteria OR 机制,而这个问题通常指的是 Hibernate OR(例如 HQL)

标签: c# sql hibernate restrictions


【解决方案1】:

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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    • 2013-11-05
    • 2010-12-13
    • 2014-11-10
    • 1970-01-01
    相关资源
    最近更新 更多