spring - how to add @onetoone mapping for self entity in hibernate -
how add one-to-one mapping self entity. in example. want have parent-child relationship person itself.
@entity @table(name="person") public class person { @id @column(name="personid") private int id; @onetoone @joincolumn() private person parentperson; }
here example of bidirectional self mapping @onetoone
(i change column names sql notation):
@entity @table(name="person") public class person { @id @column(name="person_id") private int id; @onetoone @joincolumn(name = "parent_person_id") private person parentperson; @onetoone(mappedby = "parentperson") private person childperson; }
but, don't understand why want use @onetoone
in case.
Comments
Post a Comment