开发者

Composite key in Hibernate Annotations confusion

开发者 https://www.devze.com 2023-04-06 11:10 出处:网络
I have two tables say \'A\' and \'B\'. A third table \'C\' has two columns that directly refer to \'A\' and \'B\' i.e. \'C\' contains \'A_id\' and \'B_id\' that refer to A\'s id and B\'s id respec开发

I have two tables say 'A' and 'B'. A third table 'C' has two columns that directly refer to 'A' and 'B' i.e. 'C' contains 'A_id' and 'B_id' that refer to A's id and B's id respec开发者_如何转开发tively. There is unique key defined on 'A_id' and 'B_id'. But there is no id column in 'C'. How can I go about defining the model class for 'C' without altering the schema for 'C'. I am very new to using Hibernate annotations so please help me out. 'A' and 'B' have other columns as well and have their model classes already defined.


It looks to me like C is just a join table. There is no need to map C explicitly. You can map relation from A to B or vice versa using @JoinTable annotation. Please take a look at the example at One To Many Join Table Setup. There is no mapping for EMP_PHONE, it is just a join table between phone and employee.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号