如何为给定的sql查询创建hibernate条件查询

时间:2014-01-31 06:44:15

标签: sql hibernate nhibernate hibernate-criteria

如何为给定的sql查询编写hibernate条件查询?

SELECT * FROM Customers
WHERE Country='Germany'
AND (City='Berlin' OR City='Munchen');

1 个答案:

答案 0 :(得分:1)

Criteria criteria = session.createCriteria(Customers.class);
criteria.add(Restrictions.eq("Country", "Germany"));
criteria.add(Restrictions.or(
                             Restrictions.eq("City", "Berlin"),
                             Restrictions.eq("City", "Munchen")));

另见