sql - HQL: using elements() on objects -
say have database 2 tables: classes , students. each table contains metadata relevant topic. example, classes contains fields 'classid', 'name' , 'room_number' , students contains fields 'name', 'classid', 'age' , 'height' (say student can in 1 class).
what if want write hql query me classes include students names 'joe', 'bob', , 'fred'? if students contained 'classid' , 'name' think write following in hql.
from classes class 'joe' in elements(class.students) , 'bob' in elements(class.students) , 'fred' in elements(class.students)
however, students object in case. need perform joins explicitly?
from classes class join class.students s1 join class.students s2 join class.students s2 s1.name = 'joe' s2.name = 'bob' s3.name = 'fred'
i imagine using 'fred' in elements
performs these joins, more compact write! or there better way of doing altogether?
use sub-select:
from classes c c.classid in( select s.classid students s s.name in('joe', 'bob', 'fred') )
Comments
Post a Comment