简体   繁体   English

我无法定义如何在另一个表的实体类中映射两个不同表的两个外键列

[英]Iam unable to define how to map two foreign key columns of two different table in Entity class of other table

Iam unable to define how to map two foreign key columns of two different table in Entity class of other table. 我无法定义如何在另一个表的Entity类中映射两个不同表的两个外键列。

let me give example of table structure 让我举一个表结构的例子

table1
   column11 (primary key)
   column12 
   column13

table2
   column21 (primary key)
   column11 (foreign key - table1 primary key column)
   column22
   column23

table3
   column31 (primary key)
   column11 (foreign key - table1 primary key column)
   column21 (foreign key - table2 primary key column)
   column32
   column33

Now i want to my entity class table3 to hold these two foreign keys. 现在我想让我的实体类table3拥有这两个外键。 Iam very new to JPA(hibernate) . 我对JPA(休眠)非常陌生。 How can i map those foreign key columns as entity class attributes? 如何将那些外键列映射为实体类属性? Please suggest me. 请给我建议。

@Entity
public class Table3 {
    // ...

    @ManyToOne
    @JoinColumn(name = "column11")
    private Table1 table1;

    @ManyToOne
    @JoinColumn(name = "column21")
    private Table2 table2;

    // ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate 映射 map 两列与其他表 - Hibernate mapping map two columns with other table 如何通过 UCanAccess 创建一个带有两个外键引用到另一个表的表? - How can I create a Table with two Foreign Key References to one other Table via UCanAccess? JPA如何从单个表的复合主键的两个不同表部分制作复合外键 - JPA how to make composite Foreign Keys from two different table part of composite Primary Key of a single table Hibernate:如何为一个表映射两列 - Hibernate: how to map two columns for one table 通过外键从没有其他实体的另一个表中获取几列 - Get few columns from another table withou other entity by foreign key 如何在两个表之间建立关联,以便子表将仅共享父表的一个字段作为外键 - How to build association between two table such that the child table will share just one field of parent table as foreign key 如何将两个 class 字段(不引用任何其他表)作为 hibernate 中的复合键? - how to make the two class fields(not referring any other table) as composite key in hibernate? 如何在Spring Boot中为只有外键的表映射/创建实体类 - How do I map/create an entity class for a table which has only foreign keys in Spring Boot 如何在 jdbc 的表中包含两个外键? - How to include two foreign keys in a table in jdbc? 是否可以在Hibernate中映射表的两列而不是两个表 - Is it possible to map two columns of table instead of two tables in Hibernate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM