Hibernate3.2以上版本中-执行sql语句返回对象list

.addEntity("base", SpaceBase.class)此方法追加实体
取出对象实体
List list = this.baseInfoDao.list(sql.toString(), start, limit, params);
Iterator it = list.iterator();

while(it.hasNext()) {
Object[] objs = (Object[]) it.next();
SpaceBase b = (SpaceBase) objs[0];
SpaceOrg o = (SpaceOrg) objs[1];
}
public List list(final String queryString, final int startIndex, final int rows, final List params) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {
SQLQuery q = session.createSQLQuery(queryString)
.addEntity("base", SpaceBase.class).addEntity("org", SpaceOrg.class);
for(int i = 0; i < params.size(); i++) {
q.setParameter(i, params.get(i));
}
if(startIndex >= 0) {
q.setFirstResult(startIndex);
}
if(rows > 0) {
q.setMaxResults(rows);
}
List list = q.list();

return list;
}
});
}

你可能感兴趣的:(hibernate3)