Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Soumya Ranjan Mohanty
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
Hibernate Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Soumya Ranjan Mohanty
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic