Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;

}

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.

If I use referencedColumn then also it doesn't work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
415 views
Welcome To Ask or Share your Answers For Others

1 Answer

  1. JPA does not allow references to non-PK columns.

  2. ReferencedColumn property is used to specify join column, when there is a composite PK in referenced table.

How can I make this work??

Normalize your database to use common PK-FK relationships. If needed - define composite PK.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...