Hi there,
Is it possible to make a foreign key unique within a table? Suppose I have entities A and B.
A:
@Entity
class A extends Serializable {
@Id
private long id;
@OneToOne
private B b;
}
B:
@Entity
class B extends Serializable {
@Id
private long id;
}
I want to make it so that an A can have a B, except there can be no other A's with the same B. Ex: a1 has b1, and a2 has b2... in this case, a3 cannot have b1 or b2 since the B's must be unique.
Is there a way to accomplish this? I'd like to be able to put the @Column( unique = true ) annotation above the @OneToOne, but this doesn't seem to be possible.