hibernate - Two attributes of the same entity -
hibernate - Two attributes of the same entity -
i have 2 entities
@entity class { @id private long id; //attributes of } @entity class b { xxx private instanceofa_1; xxx private instanceofa_2; }
as see, have 2 attributes of type in class b.
how annotate these 2 attributes in hibernate ? in end, in database, expect find 2 columns in table b, each column containing key id in table a.
i guess simple orm question, didn't manage alone...
edit : after response above, suggest next ?
@entity class { @id private long id; //attributes of } @entity class b { @manytoone private instanceofa_1; @manytoone private instanceofa_2; }
this create next tables ?
table id attributes table b a_id_1 a_id_2
how specify name of columns in table b (i.e. a_id_1 , a_id_2) ?
this rather typical situation, each of them should annotated @manytoone. @onetoone should used if per relation 1 b can related given a. if database schema generated entities, @onetoone there unique constraint in foreign key.
@joincolumn can used specify name of foreign key column:
@joincolumn(name="preferred_column_name")
hibernate
Comments
Post a Comment