yanghang888888
2017-09-11 09:55
采纳率: 7.7%
浏览 2.3k

hibernate 返回集合怎么转实体对象

我的hibernate后台查出一个集合, public List selectUserPwdByIsadmin() {
SessionFactory sessionFactory = this.getHibernateTemplate().getSessionFactory();
Session session = sessionFactory.openSession();
String hqlSelect = "select unit,pwd from aca_resource_subaccount where isadmin=1";
List list = session.createSQLQuery(hqlSelect).list();
return list;

}在action里面怎么转成AcaResourceSubaccount实体获取我想要的数据,我遍历用报错,说object没办法转成AcaResourceSubaccount

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 粘死人的冬瓜糖 2017-09-11 10:14

    你把hql语句改成from aca_resource_subaccount where isadmin=1试试,然后再遍历集合

    打赏 评论
  • yanghang888888 2017-09-11 10:23

    public List selectUserPwdByIsadmin() {
    SessionFactory sessionFactory = this.getHibernateTemplate().getSessionFactory();
    Session session = sessionFactory.openSession();
    String hqlSelect = "select unit,pwd from aca_resource_subaccount where isadmin=:isadmin";
    SQLQuery createSQLQuery = session.createSQLQuery(hqlSelect);
    createSQLQuery.setBigDecimal("isadmin", new BigDecimal("1"));
    createSQLQuery.setResultTransformer(Transformers.aliasToBean(AcaResourceSubaccount.class));
    List list=null;
    list=createSQLQuery.list();
    session.close();
    return list;
    }已经解决了,谢谢了 这样的话action里就能遍历了

    打赏 评论

相关推荐 更多相似问题