0

what i want to do is to build an HQL Query which accepts a list of ids and returns a list of loaded objets. After a while, i found that something like this could work

from Foo foo where foo.ID in (:IdList)

However, this only works for single ids beacuse when i try to use it for composite ids the app throws the next exception:

System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

I'm clueless...

I created a custom type for my id object hoping i could explain hibernate how to use it but it didnt work out.

So do you have any ideas?

thanks

Watt
  • 37
  • 5

1 Answers1

0

i cant think of a sqlquery which can do this (In cant take pairs as input as far as i know)

would this suffice (on the top of my head, cant test it right now)?

var query = "from Foo foo where ";

for (int i = 0; i < idlist.Count; i++)
{
    query += "OR foo.ID = :p" + i;
}

var hqlquery = session.CreateQuery(query);
for (int i = 0; i < idlist.Count; i++)
{
    hqlquery.SetParameter("p" + i, idlist[0]);
}
Firo
  • 30,626
  • 4
  • 55
  • 94