sql查询结果封装到实体
Configuration cfg = new Configuration().configure("hibernate.cfg.xml");
SessionFactory sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
String queryString = "select a.user, b.dept from user a, dept b where a.deptid=b.deptid";
List list = session.createSQLQuery(queryString).setResultTransformer(Transformers.aliasToBean(PojoBean.class)).list();
transaction.commit();
session.close();
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
PojoBean bean = (PojoBean) iterator.next();
}