-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: problems on persisting the child entity.
PostPosted: Mon Jun 28, 2010 6:26 am 
Newbie

Joined: Mon Jun 28, 2010 5:38 am
Posts: 1
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....................


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.