Question

How can I write hibernate criteria query for given sql query?

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

Solution

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

See Also

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top