1. 查询整个映射对象所有字段(查询整个映射对象所有字段,填充到List<User>中)
List<User> result = hibernateTemplate.executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery("from User as u");
List<User> result = query.list();
return result;
}
});
return result;
List<User> result = hibernateTemplate.executeFind(new HibernateCallback(){ public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery("select name from User as u"); List<String> result = query.list(); return result; } }); return result;
List result = hibernateTemplate.executeFind(new HibernateCallback(){ public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery("select name,pass,registeredTime from User as u"); List result = query.list(); return result; } }); return result;
遍历这个Object数组
List name = new ArrayList(); for (int i = 0; i < result.size(); i++) { Object[] objArray = (Object[])result.get(i); for(Object obj : objArray){ name.add(obj); } }
List<User> result = hibernateTemplate.executeFind(new HibernateCallback(){ public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery("select new com.bict.entity.User(u.id,u.name,u.pass,u.registeredTime) from User as u"); query.setFirstResult((pageNum - 1) * Pagination.PAGESIZE); query.setMaxResults(Pagination.PAGESIZE); List<User> result = query.list(); return result; } }); return result; }