Reputation: 2990
@Entity
class A {
@Id
int id;
}
@Entity
class B {
@Id
@OneToOne
A a;
}
B object never refer to same A object, so I want a.id to be the id of B.
How to write the annotation?
Upvotes: 2
Views: 451
Reputation: 5003
Change the B object to the following:
@Entity
class B {
@Id
int id;
@OneToOne
@MapsId
A a
}
See the hibernate documentation on OneToOne.
Upvotes: 3