I have two related entities being mapped by JPA annotations backed by hibernate. The entities both have sequence-backed identity columns in oracle. Our also have monthly partitions, represented by a column called ENTRY_DATE.
T_MASTER T_JOINED
--------- -----------
MASTER_ID JOINED_ID
ENTRY_DATE ENTRY_DATE
MASTER_ID(FK)
... ....
To gain the benefit of the partition key, I’d like Hibernate to join on both the identity IDs and the partition key, but when I use the following annotation in the Joined class:
@ManyToOne
@JoinColumns(value={
@JoinColumn(name="MASTER_ID"),
@JoinColumn(name="ENTRY_DATE")})
private Master master;
I get errors about having too many join columns. I am forced to use
@JoinColumn(name="MASTER_ID")
private Master master;
I’m a bit of a JPA/Hibernate noob. Is it possible to use a partition key in addition to the primary key when joining to related entities?
Thanks!
You probably need to declare both columns as parts of composite primary key in
Master. Hibernate would not care that much about what is real PK in the database. Mapping wil be slightly more complex with @Embeddable but it should solve the problem.