Hibernate Annotations 中的复合键混乱
我有两张表,分别为“A”和“B”。第三个表“C”具有直接引用“A”和“B”的两列,即“C”包含分别引用A的id和B的id的“A_id”和“B_id”。 “A_id”和“B_id”上定义了唯一的键。但“C”中没有 id 列。如何在不更改“C”架构的情况下定义“C”的模型类。我对使用 Hibernate 注释非常陌生,所以请帮助我。 “A”和“B”还有其他列,并且已经定义了它们的模型类。
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 respectively. 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,C 只是一个连接表。无需显式映射 C。您可以使用 @JoinTable 注释将关系从 A 映射到 B,反之亦然。请查看一对多联接表设置中的示例。 EMP_PHONE 没有映射,它只是电话和员工之间的连接表。
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.