2008-06-04
Hibernate级联查询
数据库中的表是树结构;
autoID是主键,groupId是上级代理代码,就是agentId。
现用hql查询:
生成Sql代码为:
select count(*) as col_0_0_
from billing.billing.tb_agents agent0_, billing.billing.tb_agents agent1_
where agent0_.groupId=agent1_.autoId and agent1_.agentId=1001
看红色部分。
现我想他不关联主键查询,实际通过groupId和agentId关联。该怎么解决呢?
<class table="tb_agents" name="com.billing.domain.Agent" >
<id name="autoId" type="int" column="autoID">
<generator class="sequence">
<param name="sequence">tb_agents_autoid_seq</param>
</generator>
</id>
<property name="agentId" column="agentId" type="int"/>
<many-to-one column="groupId" class="com.billing.domain.Agent" name="agent"/>
</class>
autoID是主键,groupId是上级代理代码,就是agentId。
现用hql查询:
select count(*) from Agent t where t.agent.agentId = 1001
生成Sql代码为:
select count(*) as col_0_0_
from billing.billing.tb_agents agent0_, billing.billing.tb_agents agent1_
where agent0_.groupId=agent1_.autoId and agent1_.agentId=1001
看红色部分。
现我想他不关联主键查询,实际通过groupId和agentId关联。该怎么解决呢?
发表评论
- 浏览: 501 次
- 性别:

- 来自: 上海

- 详细资料
搜索本博客
最新评论
-
一个createQuery(hql)问题
不用 手动 关闭 session吧? 用 spring管理后, 怎么样拿到的 s ...
-- by shanglo -
一个createQuery(hql)问题
是这样的,在Hibernate中 获取session的两种方式:this.get ...
-- by kane82 -
00000
运行后报错: javax.servlet.ServletException: E ...
-- by kane82 -
难道上海找份工作就这么难 ...
简历能看出个什么名堂.
-- by mylifestyle1225 -
难道上海找份工作就这么难 ...
这个世界基本搞不清楚了,找工作的找不到,招聘的说招不到人
-- by cjmcn-sh






评论排行榜