我只是Hibernate的初学者,我想执行此查询,但是我不知道该如何..有什么帮助吗?
SELECT DISTINCT agents.username
FROM users u
INNER JOIN UserDistributors ud
ON u.id = ud.[user]
INNER JOIN users agents
ON agents.type =9
INNER JOIN UserDistributors agentsdistributor
ON agentsdistributor.distributor = ud.distributor
AND agents.id=agentsdistributor.[user]
WHERE u.id=1778
我的user.hbm文件与分发服务器有一对多关系
<set name="userDistributors" table="UserDistributors"
inverse="true" lazy="true" fetch="select">
<key>
<column name="[user]" not-null="true" />
</key>
<one-to-many class="net.tedata.dp.model.UserDistributors" />
</set>
最佳答案
尝试这个
Criteria c = session.createCriteria(User.class);
c.createAlias("ud", "UserDistributors"); // inner join by default
c.add(Restrictions.eq("ud.id", "<Name>"));