java - hibernate self referencing table get rows by fk -


table student ---------------- id  | somecolumn string| fk(which self referencing id of same table) 

how can make hibernate query fetch items value of id match value of fk.

here have tried doesn't works (it returns 1 result instead of result set)

list<student> list = (list<student>) sessionfactory             .getcurrentsession()             .createquery("from student p join p.studentfks p2 p2.id = :parentid")             .setparameter("parentid", parentid).list(); 

can me solve mistery? know can achieved hibernate criterias also.

update answer change query to(join invalid.. ):

select p student p join p.student p2 p2.id = :parentid 

i use , work

property of join inside entity student :

@manytomany(cascade = cascadetype.refresh) private set<student> testjoins = new hashset<student>(); 

hql set :

select a.testjoins student a.id = :parentid 

maybe can change query p2.id = :parentid to-->> p.id = :parentid


Comments