Hi lightbulb,
You should use JoinColumn for that:
ex:
Code:
@Entity
class EntityA {
long id;
long uniqueKey;
}
Code:
@Entity
class EntityB {
@ManyToOne
@JoinColumn(name="Referenced_Unique_Key", referencedColumnName="uniqueKey")
EntityA parent;
}
this way you should have a column in EntityB with the name Referenced_Unique_Key that points to EntityA.uniqueKey
I didn't try it, but it should work I think. Anyway, it's a bad practice to have composed keys, there's always a solution to have one key per table. Did you try to have a one to many relationship on EntityA in which you put your second key? (let's say EntityA_Annex with its own id and pointing to EntityA, then have EntityB look to the primaryKey of EntityA_Annex )
A <--(A.id)-- A_Annex <--(A_Annex.id)-- B
Hope it helped...