Indeed, uniqueResult expects only one result to be returned, so essentially, you use this with a unique query or a query against a primary key, typically.
http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=08masteringhqlandnamedqueries
For potential multiple results, you can call the list or iterate method, which will return a collection you can then loop over at your leisure.
Here's an example of a non-unique query:
Code:
Session session = HibernateUtil.beginTransaction();
String hql;
hql= "from User as u GROUP BY u.id HAVING u.id > 4)";
Query query = session.createQuery(hql);
List users = query.list();
for (int i = 0; i < users.size(); i++) {
User user = (User) users.get(i);
System.out.println("Hello World");
System.out.println(user.getLoginName());
}
HibernateUtil.commitTransaction();
http://jpa.ezhibernate.com/Javacode/lea ... medqueries