java - HQL Join with three tables -
i'm having issues hql since i'm newbie it. though don't have issues "simple queries", stuck query between 3 tables.
i read tutorials, can't find valid example needs. best explain problem:
i have 3 different tables, let's name them houses
, owners
, , ownerinfos
.
given town id, need list houses town, including name , surname of house's owner.
i made simple graph show connections between tables:
i'm unsure on join strategy should use. kind of highly appreciated, since solving priority me.
thanks in advance!
it template
class house { @manytoone(fetch = fetchtype.lazy) @joincolumn(name = "fk_town") private town town; @onetomany(mappedby = "house") private list<owner> owners; } class owner { @manytoone(fetch = fetchtype.lazy) @joincolumn(name = "fk_house") private house house; @onetoone @joincolumn(name = "fk_owner_info") private ownerinfo ownerinfo; } class ownerinfo { @onetoone(mappedby = "ownerinfo", fetch = fetchtype.lazy) private owner owner; }
the simplest case fetch owners owner info
from house h inner join fetch h.owners h.town.id = :townid
Comments
Post a Comment