Hi,
I've just got a question regard HQL which i have been unable to find any answer to anywhere else.
Say i've got the following code:
Code:
Query q1 = sess.createQuery("from Track t where t.flag = :flag");
q1.setInteger("flag", 2);
List tracks = q1.list();
Query q2= sess.createQuery("from Track t left join fetch t.files where t in (:tracks);");
q2.setParameter("tracks", tracks);
I use setParameter("tracks", tracks) to use the tracks returned from the first query as a parameter in the
second query.
Now, should this work? Should Hibernate automatically know that it should use the id property of the Track entity
to compare items in the 'in'-clause? The alternative would be to use:
Code:
Query q1= sess.createQuery("select t.id from Track t where t.flag = :flag");
q1.setInteger("flag", 2);
List trackIds = q1.list();
Query q2 = sess.createQuery("from Track t left join fetch t.files where t.id in (:trackIds);");
q2.setParameter("trackIds", trackIds);
Love to hear any input on this one!