Is it possible to reference another JPA entity with an id
instead of a Java reference?
We have this entity which references a Person entity.
Instead of having the referencePerson
property we would
want it to replace with a referencePersonId
property
@Entity
@PrimaryKeyJoinColumn(name = "ID")
public class PersonReference {
@Id
private Long id;
@ManyToOne
@JoinColumn(name = "PERSON_ID")
private Person referencePerson;
}
new version should look similar to this
@Entity
@PrimaryKeyJoinColumn(name = "ID")
public class PersonReference {
@Id
private Long id;
// reference Person entity somehow
@JoinColumn(name = "PERSON_ID")
private Long referencePersonId;
}
Is it possible with JPA to have that with a foreign key constraint and
cascaded delete, that is when a Person object with a given
id is deleted also matching PersonReference entities are deleted