让hibernate支持递归、start with connect by prior 查询

原创 2012年03月28日 13:11:28

由于hibernate的结果对象映射功能很好用,但是有些特殊的sql文hibernate并不支持,比如start with  connect by prior,如何让hibernate支持这种特殊sql查询,还能使用hibernate的对象功能呢。方法如下:

1、普通sql文:select {city.*} from T_IP_CITY_INVEST city start with city.PROFESSION_AUDITOR = ‘wuy’ connect by prior city.PARENT_PROJECT_CODE = city.PROJECT_CODE  and  order by city.id

2、使用方法
this.getSession().createSQLQuery(sql).addEntity(“city”, TIpCityInvest.class)
 .list();即可,从上面可以看出,和普通sql文最大的区别就是 {city.*},这个实际上就是把查询结果集转为映射对象。

3、hibernate解析后的sql文:

Hibernate:
    select
        city.ID as ID115_0_,
        city.PROJECT_CODE as PROJECT2_115_0_,
        city.PROJECT_NAME as PROJECT3_115_0_,
        city.PARENT_PROJECT_CODE as PARENT4_115_0_,
        city.CHILD_COUNT as CHILD5_115_0_,
        city.PLAN_YEAR as PLAN6_115_0_,
        city.PLAN_VERSION as PLAN7_115_0_,
        city.PROFESSION_AUDITOR as PROFESSION8_115_0_,
        city.CARRY_OVER_REGION as CARRY9_115_0_,
        city.PROJECT_AMOUNT_REGION as PROJECT10_115_0_,
        city.PROJECT_YEAR_REGION as PROJECT11_115_0_,
        city.PROJECT_YEAR_COUNT_REGION as PROJECT12_115_0_,
        city.CARRY_OVER_NANJING as CARRY13_115_0_,
        city.PROJECT_AMOUNT_NANJING as PROJECT14_115_0_,
        city.PROJECT_YEAR_NANJING as PROJECT15_115_0_,
        city.PROJECT_YEAR_COUNT_NANJING as PROJECT16_115_0_,
        city.CARRY_OVER_SUZHOU as CARRY17_115_0_,
        city.PROJECT_AMOUNT_SUZHOU as PROJECT18_115_0_,
        city.PROJECT_YEAR_SUZHOU as PROJECT19_115_0_,
        city.PROJECT_YEAR_COUNT_SUZHOU as PROJECT20_115_0_,
        city.CARRY_OVER_WUXI as CARRY21_115_0_,
        city.PROJECT_AMOUNT_WUXI as PROJECT22_115_0_,
        city.PROJECT_YEAR_WUXI as PROJECT23_115_0_,
        city.PROJECT_YEAR_COUNT_WUXI as PROJECT24_115_0_,
        city.CARRY_OVER_CHANGZHOU as CARRY25_115_0_,
        city.PROJECT_AMOUNT_CHANGZHOU as PROJECT26_115_0_,
        city.PROJECT_YEAR_CHANGZHOU as PROJECT27_115_0_,
        city.PROJECT_YEAR_COUNT_CHANGZHOU as PROJECT28_115_0_,
        city.CARRY_OVER_NANTONG as CARRY29_115_0_,
        city.PROJECT_AMOUNT_NANTONG as PROJECT30_115_0_,
        city.PROJECT_YEAR_NANTONG as PROJECT31_115_0_,
        city.PROJECT_YEAR_COUNT_NANTONG as PROJECT32_115_0_,
        city.CARRY_OVER_ZHENJIANG as CARRY33_115_0_,
        city.PROJECT_AMOUNT_ZHENJIANG as PROJECT34_115_0_,
        city.PROJECT_YEAR_ZHENJIANG as PROJECT35_115_0_,
        city.PROJECT_YEAR_COUNT_ZHENJIANG as PROJECT36_115_0_,
        city.CARRY_OVER_YANGZHOU as CARRY37_115_0_,
        city.PROJECT_AMOUNT_YANGZHOU as PROJECT38_115_0_,
        city.PROJECT_YEAR_YANGZHOU as PROJECT39_115_0_,
        city.PROJECT_YEAR_COUNT_YANGZHOU as PROJECT40_115_0_,
        city.CARRY_OVER_TAIZHOU as CARRY41_115_0_,
        city.PROJECT_AMOUNT_TAIZHOU as PROJECT42_115_0_,
        city.PROJECT_YEAR_TAIZHOU as PROJECT43_115_0_,
        city.PROJECT_YEAR_COUNT_TAIZHOU as PROJECT44_115_0_,
        city.CARRY_OVER_XUZHOU as CARRY45_115_0_,
        city.PROJECT_AMOUNT_XUZHOU as PROJECT46_115_0_,
        city.PROJECT_YEAR_XUZHOU as PROJECT47_115_0_,
        city.PROJECT_YEAR_COUNT_XUZHOU as PROJECT48_115_0_,
        city.CARRY_OVER_YANCHENG as CARRY49_115_0_,
        city.PROJECT_AMOUNT_YANCHENG as PROJECT50_115_0_,
        city.PROJECT_YEAR_YANCHENG as PROJECT51_115_0_,
        city.PROJECT_YEAR_COUNT_YANCHENG as PROJECT52_115_0_,
        city.CARRY_OVER_HUAIAN as CARRY53_115_0_,
        city.PROJECT_AMOUNT_HUAIAN as PROJECT54_115_0_,
        city.PROJECT_YEAR_HUAIAN as PROJECT55_115_0_,
        city.PROJECT_YEAR_COUNT_HUAIAN as PROJECT56_115_0_,
        city.CARRY_OVER_LIANYUNGANG as CARRY57_115_0_,
        city.PROJECT_AMOUNT_LIANYUNGANG as PROJECT58_115_0_,
        city.PROJECT_YEAR_LIANYUNGANG as PROJECT59_115_0_,
        city.PROJECT_YEAR_COUNT_LIANYUNGANG as PROJECT60_115_0_,
        city.CARRY_OVER_SUQIAN as CARRY61_115_0_,
        city.PROJECT_AMOUNT_SUQIAN as PROJECT62_115_0_,
        city.PROJECT_YEAR_SUQIAN as PROJECT63_115_0_,
        city.PROJECT_YEAR_COUNT_SUQIAN as PROJECT64_115_0_,
        city.BATCHNUMBER as BATCHNU65_115_0_,
        city.PROFESSION_AUDITOR_NAME as PROFESSION66_115_0_
    from
        T_IP_CITY_INVEST city start with city.PROFESSION_AUDITOR = ‘wuy’
         connect   by prior city.PARENT_PROJECT_CODE = city.PROJECT_CODE 
    order by
        city.id

hibernate4实战1—入门

hibernate4实战入门1
  • u011518709
  • u011518709
  • 2014年12月09日 17:11
  • 1502

让hibernate支持递归、start with connect by prior 查询

由于hibernate的结果对象映射功能很好用,但是有些特殊的sql文hibernate并不支持,比如start with  connect by prior,如何让hibernate支持这种特殊sq...
  • m13666368773
  • m13666368773
  • 2012年03月28日 13:11
  • 6486

Oracle中的递归查询语法(start with...connect by prior)

select * from table1 start with id='0' connect by prior id = parentid     查询id等于0的节点下面的所有子节点     s...
  • u014227966
  • u014227966
  • 2014年04月16日 10:48
  • 1151

ORACLE查询树型关系(start with connect by prior)

oracle中的select语句可以用START WITH...CONNECT BY PRIOR子句实现递归查询,connect by 是结构化查询中用到的,其基本语法是: select * from...
  • amork
  • amork
  • 2009年07月20日 16:36
  • 8647

MyEclipse_Hibernate_Quickstart

  • 2007年04月25日 16:43
  • 481KB
  • 下载

Hibernate 开发指南

Original Author: 夏昕xiaxin@gmail.com>本文是由笔者2003 年底一个咨询项目中,为客户做的持久层设计培训文案整理而来。其中的内容涉及Hibernate 的使用,以及一...
  • x51x
  • x51x
  • 2004年10月08日 20:43
  • 3063

[层次结构|树状结构] oracle中用start with...connect by prior子句实现递归查询

oracle 家族树 语法: select column from table_name start with column=value connect by prior 父主键=子主键 --自顶向...
  • hellojoy
  • hellojoy
  • 2015年11月13日 16:29
  • 931

sqlserver实现oracle递归树函数样例(start with.....connect by prior)

所要用到的两张表:   with.....connect by prior)" name="image_operate_37511323672877890" alt="sqlserver实现ora...
  • key_the_one
  • key_the_one
  • 2012年01月31日 15:01
  • 1849

在WebLogic中使用Hibernate

   关于这个话题,javaeye其实有一篇文章专门介绍了(http://www.javaeye.com/viewtopic.php?t=245),但是可能不是很详细,最近也有一些人我这方面的问题,所...
  • jayliu
  • jayliu
  • 2005年07月11日 19:10
  • 3321

Hibernate的体系结构

第 2 章 体系结构 2.1. 总览 对Hibernate非常高层的概览: 这幅图展示了Hibernate使用数据库和配置文件数据来为应用程序提供持久...
  • holandstone
  • holandstone
  • 2014年04月14日 15:41
  • 2120
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:让hibernate支持递归、start with connect by prior 查询
举报原因:
原因补充:

(最多只允许输入30个字)