Hi guys,
i am facing some problem on saving the child entity together with the parent entity.
here is my codition:
i have an entity named Employee, and this employee entity is having a list of sub record named WorkExperience. so i once in persist the employee entity, all it's sub records(WorkExperience) will be persist as well. but my problem is, in the table structure of the workExperience, the foreign key for workExperience to link to the Employee entity must not in not-null constraints, if not the db will throws me constraint violation exception. i understand that this action will issue two sql statement :
1) insert record for WorkExperience(without foreign key). 2) update the link(WorkExperience's foreign key) betwee Employee and WorkExperience. so the first sql statement will violate the not null constraints.
here is some code inside my Employee entity :
Code:
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
@JoinColumn(name = "emp_id")
@org.hibernate.annotations.Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private List<WorkExperience> workExperienceList = new ArrayList();
do you guys have any suggestion or recommendation on this issue?
hope to hear from you guys soon, and Thanks in advance....................