方法:利用Query接口的setResultTransformer()方法
条件:只要该普通javaBean提供setter与getter方法即可
Eg:
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();
}