简体   繁体   English

一个表可以使用休眠模式具有两列相同的外键吗?

[英]Can a table have two columns of same foreign keys using hibernate?

I need to have 2 columns in table B. Say column_1 one and column_2. 我需要在表B中有2列。说一列_1和一列_2。 Currently Table B has column_1. 当前表B具有column_1。

Both column_1 and column_2 are primary key in Table A. column_1和column_2都是表A中的主键。

Table A is an Entity Class and Table B is an Entity Class as well. 表A是一个实体类,表B也是一个实体类。

column_1 is mapped as follows column_1映射如下

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "column_1", nullable = false)
private A a;

The Question here is, is this possible to do? 这里的问题是,这可能吗? If yes how should it be done? 如果是,应该怎么做?

I figured it out. 我想到了。

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "column_1", nullable = false)
private A a;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "column_2", nullable = false)
private A b;

Map the variables a and b to a list in Class A. 将变量a和b映射到A类中的列表。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM