Reputation: 467
I want todo a simple join, well just comparing the ID's in two tables..
I have my Group Table, containing;
And i have my GroupMap Table containing;
My query takes a GroupMap.ItemID and is meant to return a list of groups that the itemID belongs to, in SQL I would have done this;
select Group.* from Group, GroupMap Where GroupMap.ItemID = '527' and Group.ID = GroupMap.GroupID;
This returns what i require, i just cant seem to replicate it in HQL, I thought it would have been quite trivial.
Thanks, James
Upvotes: 2
Views: 5514
Reputation: 17957
You can use a theta join in hql
select g from Group g, GroupMap m Where m.ItemID = '527' and g.ID = m.GroupID
Upvotes: 8
Reputation: 56934
With a HQL, you do not think in terms of tables and relations between those tables, but in entities and associations between those entities.
So, if you have the Group and GroupMap classes (which you've mapped to your DB tables), you'll have to write your HQL something like this:
from Group as g inner join g.Maps as m where m.ItemID = '527'
That is, supposing your Group entity has a collection of GroupMap entities ...
Upvotes: 3