Reputation: 29
I am just a beginner in Hibernate, I would like to execute this query but I don't know how .. any help please?
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
my user.hbm file has one to many relation to distributor
<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>
Upvotes: 0
Views: 105
Reputation: 327
Try this
Criteria c = session.createCriteria(User.class);
c.createAlias("ud", "UserDistributors"); // inner join by default
c.add(Restrictions.eq("ud.id", "<Name>"));
Upvotes: 1