zhangrunzgz
zhangrunzgz
2009-08-10 15:50
浏览 267
已采纳

关于hibernate的query问题

问题是这样的,
[code="java"]hql="select new PersonBasicInfo(bid,name,rynumber)
from PersonBasicInfo
where status.id=1 and flag='1' and personAdditionalInfo.personCategory.sortID not in(23)

and personAdditionalInfo.department.path like '.1.2.11.%' or personAdditionalInfo.department.path='.1.2.11'
order by name"
// 执行查询
Query query = session.createQuery(hql);
list = query.list();
//执行list之后,打印出来的hql为:
"select personbasi0_.RYID as col_0_0_, personbasi0_.XM as col_1_0_, personbasi0_.RYBH as col_2_0_
from RS_RYJBXX personbasi0_, RS_RYQTXX personaddi1_, RS_BM department3_
where personbasi0_.RYID=personaddi1_.RYID and personaddi1_.BMID=department3_.ID
and (personbasi0_.DQZTM=1 and personbasi0_.FLAG='1' and (personaddi1_.RYLB not in (23))
and (department3_.PATH like '.1.2.11.%') or department3_.PATH='.1.2.11')
order by personbasi0_.XM "[/code]

谁能给解释下,搞不懂啊,执行的到底是那个hql啊?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • wanghaolovezlq
    wanghaolovezlq 2009-08-24 10:10
    已采纳

    hibernate中的hql和sql是不一样的,hql是封装了sql,由hibernate的语法引擎解析生成sql,数据库里只能执行sql语句,不能执行hql啊

    hql只是特定于hibernate的语句

    //执行list之后,[color=red]打印出来的是sql语句,正确在数据库中执行的语句 [/color]"select personbasi0_.RYID as col_0_0_, personbasi0_.XM as col_1_0_, personbasi0_.RYBH as col_2_0_

    from RS_RYJBXX personbasi0_, RS_RYQTXX personaddi1_, RS_BM department3_

    where personbasi0_.RYID=personaddi1_.RYID and personaddi1_.BMID=department3_.ID

    and (personbasi0_.DQZTM=1 and personbasi0_.FLAG='1' and (personaddi1_.RYLB not in (23))

    and (department3_.PATH like '.1.2.11.%') or department3_.PATH='.1.2.11')

    order by personbasi0_.XM "

    点赞 评论
  • ghost1000
    ghost1000 2009-08-10 17:38

    [code="java"]new PersonBasicInfo(bid,name,rynumber)[/code]
    这句话是new 出来一个实体,实体里面有个构造函数(bid,name,rynumber);

    [code="java"]where status.id=1 and flag='1' and personAdditionalInfo.personCategory.sortID not in(23)

    and personAdditionalInfo.department.path like '.1.2.11.%' or personAdditionalInfo.department.path='.1.2.11'

    order by name" [/code]

    这些是条件查询和字段模糊查询。

    执行的是[code="java"]hql="select new PersonBasicInfo(bid,name,rynumber)

    from PersonBasicInfo

    where status.id=1 and flag='1' and personAdditionalInfo.personCategory.sortID not in(23)

    and personAdditionalInfo.department.path like '.1.2.11.%' or personAdditionalInfo.department.path='.1.2.11'

    order by name"

    [/code]

    这个hql就是把查询的语句放在里面。没什么难的

    点赞 评论

相关推荐