This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes delete option of cascade in Hibernate one-to-one association Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "delete option of cascade in Hibernate one-to-one association" Watch "delete option of cascade in Hibernate one-to-one association" New topic
Author

delete option of cascade in Hibernate one-to-one association

Soumya Ranjan Mohanty
Ranch Hand

Joined: Mar 07, 2010
Posts: 44
I am not able to delete the corresponding one-to-one relation row using delete option of cascade. Here are the code for my class and Mappings.

Code For Employee.java Class.



Code for PersonalDetails.java Class

mapping -- Employee.hbm.xml



mapping- PersonalDetails.hbm.xml



When i delete any row from Employee table the Corresponding Foreign key row in PersonalDetails Table is not deleting. Please Help Me.

Thanks

joy b chakravarty
Ranch Hand

Joined: May 16, 2011
Posts: 62

Interesting.. Not exactly sure why this one-to-one bidirectional relation is giving you trouble.

Can you try removing this
<generator class="foreign">
<param name="property">personalDetails</param>
</generator>

and instead have the following in the mapping- PersonalDetails.hbm.xml

<generator class="foreign">
<param name="property">emp</param>
</generator>


Cheers, Joy [SCJP 1.4, SCBCD 5.0]
get high on alcohol, algorithm or both
Soumya Ranjan Mohanty
Ranch Hand

Joined: Mar 07, 2010
Posts: 44
i did exactly what you said and it's working fine. Thanks a lot joy b chakravarty .Can you please explain what was the mistake so that i can clear my doubt.

Again Thanks a lot.
joy b chakravarty
Ranch Hand

Joined: May 16, 2011
Posts: 62

In a relationship, there is an owning side, here what you wanted is Employee as the owing side.
with your earlier configuration PersonalDetails became the owing side as the PersonalDetails 'eno' was assigned to an employee which shouldn't have been the case.
reversing that made Employee the owing side. Hope this helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: delete option of cascade in Hibernate one-to-one association