数据库中的表是树结构;
autoID是主键,groupId是上级代理代码,就是agentId。
现用hql查询:
生成Sql代码为:
select count(*) as col_0_0_
from billing.billing.tb_agents agent0_, billing.billing.tb_agents agent1_
where [b][color=red]agent0_.groupId=agent1_.autoId[/color][/b] 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 [b][color=red]agent0_.groupId=agent1_.autoId[/color][/b] and agent1_.agentId=1001
看红色部分。
现我想他不关联主键查询,实际通过groupId和agentId关联。该怎么解决呢?