我有这段代码
String sql = "distinct from com.zrsol.admin.shared.StatesProvinces";
Session session = sessionFactory.openSession();
Query query = session.createQuery(sql);
List rsList = query.list();
for (Iterator it = rsList.iterator();
it.hasNext();) {
statesProvinces = (StatesProvinces) it.next();
allStates.add(statesProvinces);
String state = statesProvinces.getState();
states.add(state);
}
return states;
}
我得到的错误:java.lang.IllegalArgumentException:要遍历的节点不能为空!
如果我从查询中删除这个“distinct”错误消失了,但是我得到了多种状态,我想要一个独特的状态
由于
答案 0 :(得分:0)
"select distinct(state) from com.zrsol.admin.shared.StatesProvinces state";
答案 1 :(得分:0)
Here's a snippet of hql that we use. (Names have been changed to protect identities)
String queryString = "select distinct f from Foo f inner join foo.bars as b" +
" where f.creationDate >= ? and f.creationDate < ? and b.bar = ?";
return getHibernateTemplate().find(queryString, new Object[] {startDate, endDate, bar});
[Reference][1]
[1]: http://stackoverflow.com/questions/263850/how-do-you-create-a-distinct-query-in-hql