I create entity class from database with foreing key, the attribute set like this:
@Entity
@Table(name = "PERSON")
//....
@JoinColumn(name = "ID_DEPARTMENT", referencedColumnName = "ID_DEPARTMENT")
@ManyToOne
private Department idDepartment;
// On the other entity class the configuration set like this
@Entity
@Table(name = "DEPARTMENT")
// ...
@OneToMany(mappedBy = "idDepartment")
private Collection<Person> personCollection;
The value of idDepartment in table Person can be null, because at the beginning you don't have that information
When I try save without this value gives the following error:
org.hibernate.TransientPropertyValueException: object references an unsaved transient instance.
but I dont need save nothing in Department... I try with cascade all, but save a blank record in table department ( this is not what I want).
How can I save the record in table person without value idDepartment?