distinct在HQL中使用
来源:互联网 发布:二次开发 软件著作权 编辑:程序博客网 时间:2024/04/25 08:10
- public static List findHBDH() {
- Transaction tx = null;
- Session session = SessionManager.currentSession();
- List<Long> list = new ArrayList<Long>();
- try {
- tx = session.beginTransaction();
- StringBuffer hqlStr = new StringBuffer(
- "select distinct xx.b1 from XXX xx");
- Query qry = session.createQuery(hqlStr.toString());
- Iterator it = qry.list().iterator();
- while (it.hasNext()) {
- list.add((Long)it.next());
- }
- } catch (Exception e) {
- if (tx != null) {
- try {
- tx.rollback();
- } catch (HibernateException ex) {
- ex.printStackTrace();
- }
- }
- e.printStackTrace();
- return null;
- } finally {
- try {
- SessionManager.closeSession();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- return list;
- }
- public static void main(String[] args) {
- //测试
- List list = new ArrayList();
- try{
- list = findHBDH();
- for(int i=0;i<=list.size()-1;i++){
- System.out.println(list.get(i));
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }
注意两点: HQL的写法"select distinct 别名.字段 from 映射类名 别名"。。。
如何存储到list。。。 list.add((Long)it.next())。。。
- distinct在HQL中使用
- 在hql中使用distinct
- 在Django中使用DISTINCT
- hql不能在distinct,group by结果集上使用count的问题,报语法错误
- 在HQL中使用Dto对象查询
- ContentProvider中使用DISTINCT
- 使用distinct在mysql中查询多条不重复记录值
- 在XSLT中对for-each语句使用distinct操作
- Kylin系列-在Apache Kylin中使用Count Distinct
- 在mysql中使用去重distinct需要注意的
- Hql语句中使用distinct关键字查询多个字段后以对象形式返回的方法
- hql中使用like
- 在hql中使用left jion 遇到的问题 org.hibernate.hql.ast.QuerySyntaxException:
- 在Hibernate中使用HQL通过Join进行关联查询
- 在Hibernate中使用HQL通过Join进行关联查询
- 在hql中设置时间参数时要使用setTimestamp
- 在项目中使用sql语句,或者是hql语句。
- 如何在hibernate+mySQL中使用HQL的cast语句
- oracle分区表学习及应用
- ASP.NET页面生命周期
- core dump
- Oracle-Bigfile and Smallfile
- debian镜像地址
- distinct在HQL中使用
- 我可以学好它吗?(制作网站)
- CBR综述(Survey, Reviews or Overviews)
- corg.apache.jasper.JasperException解决办法
- Spring 中加载资源文件
- .NET框架与COM
- CSS 滤镜大全 - 北漂石头的博客
- Eclipse快捷键操作集合
- gdb 调试