hibernate查询返回list无法转换对象
有这样一段代码,返回的list无法转换成User对象
public List<User> getStoreList(final int pageNo,final int pageSize,final String role,final String check) { //type is cpUser 商品type String hql=""; if(check.equals("通过")){ hql = "from User user inner join user.roles as role where role.name='" + role + "' and user.extAttributes.attr3='通过' order by user.id desc"; }else{ //未通过,扩展可直接扩展终态hql hql = "from User user inner join user.roles as role where role.name='" + role + "' and user.enabled=false and user.extAttributes.attr3='未审核' order by user.id desc"; } final String query = hql; List list = (List)this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { return session.createQuery(query) .setFirstResult((pageNo-1)*pageSize) .setMaxResults(pageSize) .list(); } }); return list; }
弄了弄,才发现!原来是hql这个出了问题,断点加上看看list的值明明就是user对象,但就是无法转换,这是因为hibernate在表连接之后,让所有的连接表一起组成了一个对象,这个hql其实是返回了2个对象
hql="selectuser"这样就搞定了,给他指定一个查询结果,不然他太勤快了都给你查询出来了,呵呵
相关推荐
LetonLIU 2020-03-28
tugangkai 2020-07-04
taisenki 2020-06-02
zzjmay 2020-05-17
shuiluobu 2020-03-20
solarspot 2014-06-27
LetonLIU 2019-12-23
东方咖啡屋 2019-12-08
浮生 2011-12-12
surpassdream 2011-12-11
keruis 2015-02-03
小黄鸡kimhuhg 2015-02-16
Lingforme 2015-07-23
bigcactus 2012-05-21
张浩BIT 2012-04-22
虽然我很菜 2016-01-08
WJI 2014-11-06
kobexing 2014-07-16
crazzylp 2014-01-08