I have two classes Person and Department and there is a many-to-one relationship between Person and Department. The save operation is normal when there is a value applied to "department" of Person. When I want to save a null value to "department" of Person, there is the following error message.
object references an unsaved transient instance - save the transient instance before flushing: webmodule.model.Department; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: webmodule.model.Department
I doubt whether there are some settings missed for the classes. Please give help on this.
Class definition below:-
Code:
public class Person {
private Integer id;
private String name;
private Department department;
@ManyToOne(fetch=FetchType.EAGER, optional=true, targetEntity=Department.class)
@NotFound(action=NotFoundAction.IGNORE)
@JoinColumn(name="department", referencedColumnName="id", nullable=true, insertable=false, updatable=true)
public Department getDepartment() {
return department;
}
// other getter and setter
}
public class Department {
private Integer id;
private String name;
// other getter and setter
}