Having two entities defining relationship by @ManyToOne
and @OneToMany
, how can I get foreign key without asking from related object and just by looking at defining tables? How do I get OWNER_ID
from Owned
by something like owned.getOwnerId()
instead of owned.getOwner().getId()
and still be able to owned.getOwner()
?
Asked
Active
Viewed 719 times
2

reith
- 2,028
- 13
- 26
1 Answers
3
Map the field in your entity as a basic mapping allows you to use the foreign key directly. You can keep the object reference mapping as well, but one of the two mappings must then be marked as insertable=false, updatable=false so that JPA knows which mapping controls the field in the event they show different values.

Chris
- 20,138
- 2
- 29
- 43