I created a Spring Web Application
with database access. I have a class Person
- which has references to a class Address
. A person has an address as well as the company, so person
and company
both refer to the Address
table. I did this by defining a @ManyToOne
relation from person to address as well as the company.
@ManyToOne
@JoinColumn (name="COMPANY_ID")
private Adress companyId;
@ManyToOne
@JoinColumn (name="SUBSIDIARY_ID")
private Adress subsidiaryId;
In the person repository I have a save method like this:
public Person save(Person entity) {
SaveAccess<Person> ao = createSaveAccess();
ao.setEntity(entity);
ao.execute();
return ao.getResult();
}
The thing is, if I try to add a new person I get a Hibernate-TransientPropertyValueException
which says Object references an unsaved transient instance - save the transient instance before flushing.
Can anyone help me here?