在非主键列上进行联接时,JPA @JoinColumn问题 [英] JPA @JoinColumn issues while joining on non primary key columns
问题描述
我想基于一个方向联接连接表,这是我的代码:
I want to connect table based on one direction join, here is my code:
Class Person {
@id
String person_sk;
int person_id;
String Person_name;
@OneToMany
@joinColumn (name="person_reference_id")
List<address> getAddresses() {}
}
class Address
{
@id
int person_reference_id (referred from Person);
@id
int address_id;
@id
int phone_id;
String street_name, zip_code;
}
现在,当我执行getAddress时,它将不起作用,因为我的联接基于Person类中的person_ref_id和@id(primaryKey)列是person_sk.
Now when I do getAddress, it does not work, because my join is based on person_ref_id and @id (primaryKey) column in Person class is person_sk.
如果我使用referencedColumn,那么它也不起作用.
If I use referencedColumn then also it doesn't work.
推荐答案
在引用表中存在复合PK时,ReferencedColumn属性用于指定连接列.. /p>
ReferencedColumn property is used to specify join column, when there is a composite PK in referenced table.
我怎么做这项工作?
How can I make this work??
规范化数据库以使用常见的PK-FK关系.如果需要-定义复合PK.
Normalize your database to use common PK-FK relationships. If needed - define composite PK.
这篇关于在非主键列上进行联接时,JPA @JoinColumn问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!