Hibernate HQL动态构造实例对象
String hql="select u.name,u.password from User u"; Query query=session.createQuery(hql); Iterator iter=query.iterator(); while(iter.next()){ Object obj[]=(Object[]iter.next()); System.out.println(obj[0]+obj[1]); }
//需要逐一去访问结果集,非常不方便
Hibernate的HQL语言提供了 动态构造实例对象的方法
String hql="select new User(u.name,u.password) from User u"; Query query=session.createQuery(hql); Iterator iter=query.iterator(); while(iter.next()){ User u=(User)it.next(); System.out.println(u.getName()+u.getPassword()); }
注意:对应实体对象中使用指定属性值的构造函数一定要存在
相关推荐
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