-->
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: cascade delete for one-to-many to unsaved=any composite-id?
PostPosted: Thu Mar 11, 2004 11:02 am 
Regular
Regular

Joined: Tue Jan 13, 2004 4:57 am
Posts: 83
I am doing experiments with a hibernate mapping that has been generated by middlegen and which I tweaked a bit in order to gain understanding of what happens in hibernate. The mapping is awful (a set contains entity objects with composite-id) and is going to be replaced by a map, but nevertheless working with it has exposed something I don't understand.

So, I have a SecurityPermission entity with a one-to-many inverse=true relationship to a SecurityPermissionAttr (attribute), whose table has a foreign key to the permissionId column of the securitypermission and a composite-id made of both the foreign key and the attribute name.

When creating attributes, since I had to set the foreign key and the composite-id at the same time, I had to use a SecurityAttrPK class, which has to be set into the constructor, and I had to specify the unsaved-value="any" attribute in order for newly created attributes to be saved (elsewhere, the primary key I had to set into the attribute to respect the FK caused an update instead of an insert).

The problem is that when I try to delete the containing SecurityPermission entity, the attributes are not deleted even if the cascade attribute is set to "all": this is because of the unsaved-value="any" and the fact that the cascade method checks if the entity is "saved", before executing the delete.

In other words, since AbstractEntityPersister.isUnsaved always returns true -> SessionImpl.isSaved returns false -> the ACTION_DELETE CascadingAction does not execute for the given attributes and the cascade is not executed.

I understand this is not a smart mapping and am going to change it soon, but where is the mistake with the configuration here indicated? I report the mapping files:

<class
name="it.slec.data.model.SecurityPermission"
table="SECURITY_PERMISSION"
>
<id
name="permissionId"
type="int"
column="PERMISSION_ID"
>
<generator class="sequence">
<param name="sequence">SEC_PERM_SEQ</param>
</generator>
</id>

<property
name="name"
type="java.lang.String"
column="NAME"
not-null="true"
length="20"
>
</property>
<property
name="description"
type="java.lang.String"
column="DESCRIPTION"
length="256"
>
</property>

<set
name="securityPermissionAttrs"
lazy="true"
inverse="true"
cascade="all"
>
<key>
<column name="PERMISSION_ID" />
</key>
<one-to-many
class="it.slec.data.model.SecurityPermissionAttr"
/>
</set>
</class>
</hibernate-mapping>

<class
name="it.slec.data.model.SecurityPermissionAttr"
table="SECURITY_PERMISSION_ATTR"
>
<composite-id name="comp_id" class="it.slec.data.model.SecurityPermissionAttrPK"
unsaved-value="any" >
<key-property
name="attrName"
column="ATTR_NAME"
type="java.lang.String"
length="16"
>
</key-property>
<!-- bi-directional many-to-one association to SecurityPermission -->
<key-many-to-one
name="securityPermission"
class="it.slec.data.model.SecurityPermission"
>
<column name="PERMISSION_ID" />
</key-many-to-one>
</composite-id>

<property
name="attrValue"
type="java.lang.String"
column="ATTR_VALUE"
not-null="true"
length="16"
>
</property>
</class>
</hibernate-mapping>


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.