NHibernate HQL – Joining

hqljoin;nhibernate

I want todo a simple join, well just comparing the ID's in two tables..

I have my Group Table, containing;

  • ID
  • Name
  • etc..

And i have my GroupMap Table containing;

  • ID
  • GroupID
  • ItemID

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

Best Answer

You can use a theta join in hql

select g from Group g, GroupMap m Where m.ItemID = '527' and g.ID = m.GroupID
Related Topic