Hello again, I was wondering if anyone has an answer for this question I previously posted.
http://forum.hibernate.org/viewtopic.ph ... highlight=
I am switching over a dao from ejb2x to hibernate3 and cannot replicate the functionality that was available with ejb2.
Summary of the problem. Have object model like such.
class User {
String id;
Role userrole;
}
class Role {
String id;
Privilege[] roleprivs;
}
class Privilege{
String id
}
Notice i have not included other simpler properties.
User has a unid directional many-to-one with role. User table has an fk column which is the pk of the role table (simple enough) .
<many-to-one name="userrole" cascade="save-update" column="userrole_fk" class="org.user.role.data.Role"/>
All works except for case where you delete a role that a user has referenced and i dont know how to update the user table to make the fk column null. Ejb2 automattically cleaned up this fk even though it was unidirectional.
Same scenario with unidirectional many-to-many between role and privilege.
<array name="privies"
table="role_privies_link"
cascade="persist">
<key column="role_id" />
<list-index column="sorterx"/>
<many-to-many column="privies_id" class="org.user.privilege.data.Privilege" foreign-key="id" />
</array>
During delete of a Privilege it will not remove entry in link table if one exists between some role and the delete privilege.
I do not want a child role to know about a user, and i do not want a child privilege to know about a role. So i think a bi directional relationship is out of the question because a relationship needs a name value, meaning a parent /parents property on the child object.
I truely thought hibernate would handle this cleanup but all cascading (if added in) in case of unidrectional is from parent to child.