HQL中的select子句
来源:互联网 发布:多源异构数据 编辑:程序博客网 时间:2024/05/16 04:35
一、select子句简介:
二、以对象数组形式返回选择的属性:
publicvoidtestSelectClauseObjectArray(){
String hql="select country.ccode,country.cname from Country as country";
Session session=CustomSessionFactory.getSession();
Query query=session.createQuery(hql);
List<Object[]> countries=query.list();
for(Object[] objects:countries){
System.out.println("编码:"+objects[0]+" 名称:"+objects[1]);
}
CustomSessionFactory.closeSession();
}
三、以list形式返回选择的属性:
publicvoidtestSelectClauseList(){
String hql="select new list(country.ccode,country.cname) from Country as country";
Session session=CustomSessionFactory.getSession();
Query query=session.createQuery(hql);
List<List> lists=query.list();
for(List list:lists){
System.out.println("编码:"+list.get(0)+" 名称:"+list.get(1));
}
CustomSessionFactory.closeSession();
}
四、以Map的形式返回选择的属性:
publicvoidtestSelectClauseMap(){
String hql="select new map(country.ccode as ccode,country.cname as cname) from Country as country";
Session session=CustomSessionFactory.getSession();
Query query=session.createQuery(hql);
List<Map> maps=query.list();
for(Map map:maps){
System.out.println("编码:"+map.get("ccode")+" 名称:"+map.get("cname"));
}
CustomSessionFactory.closeSession();
}
五、以自定义类型返回选择的属性:
publicvoidtestSelectClauseSelf(){
String hql="select new Country(country.ccode,country.cname) from Country as country";
Session session=CustomSessionFactory.getSession();
Query query=session.createQuery(hql);
List<Country> countries=query.list();
for(Countrycountry:countries){
System.out.println("编码:"+country.getCcode()+" 名称:"+country.getCname());
}
CustomSessionFactory.closeSession();
}
六、使用distinct关键字去除重复的记录:
publicvoidtestDistinct(){
String hql="select distinct country.cname from Country as country";
Session session=CustomSessionFactory.getSession();
Query query=session.createQuery(hql);
List<Object> list=query.list();
for(Object country:list){
System.out.println("国家:"+country);
}
CustomSessionFactory.closeSession();
}
阅读全文
0 0
- HQL中的select子句
- Hibernate hql select子句
- 6.4.4:HQL查询的select子句
- select 子句
- Hibernate hql where子句
- Hibernate关闭缓存,HQL子句
- HQL 语法 限制-where子句
- Hibernate hql 定义,from 子句
- 2012-11-16 hibernate锁、hql联接查询、where子句中的boolean条件
- Hibernate HQL 中的select new map 使用实例 嵌套Map
- 6.4.2:HQL查询的from子句
- 6.4.7:HQL查询的where子句
- hibernate之HQL之order by子句
- hibernate之HQL之group by子句
- hql select from
- HQL select 总结
- HQL select 总结
- HQL select 总结
- 巧用Android网络通信技术,在网络上直接传输对象
- HDU 1004 Let the Balloon Rise
- Java 数据类型(一)
- bzoj 4612: [Wf2016]Forever Young
- 单例模式
- HQL中的select子句
- SpringBoot14-springboot核心-外部配置,日志配置,Profile配置
- JS序列化
- OpenCV 图像金字塔 pyrDown 和pyrUp函数
- 86. Partition List
- Android官方提供的支持不同屏幕大小的全部方法
- 寻找最大数(三)
- Invalid argument looking up property
- MyEclipse IDE中高效应用Hibernate