• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One-to-many mapping using SET

 
Kruti Bhan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a parent class with one-to many-child classes (unidirectional) which in return has more one/many child classes and so on. The problem i am facing is when we try to delete an entity from the parent class, the child elements still persist in the database.

Parent hbm.xml

<composite id>
<key-column name = id1>
<key-column name = id2>
</composite-id>

<set class = child cascade="all" inverse="false">
<key>
<column name = id1>
<column name = id2>
<one-to-many = child>
</key>

Child class
<composite id>
<key-column name = id1>
<key-column name = id2>
</composite-id>

<set class = sub-child cascade="all" inverse="false">
<key>
<column name = id3>
<column name = id4>
<one-to-many = sub-child>
</key>

Sub-child class
<composite id>
<key-column name = id3>
<key-column name = id4>
</composite-id>

<property-name = prop1>

Test class
Entity entity = session.load(Clazz.class, serializable id)
session.delete(entity);

Please note the key columns will be repeated in each of the tables (we do not use foreign keys). Also, these relations are uni-directional. The primary key has to be referencing both the columns.

The insert function works fine and add values at all levels. Am i missing out something in the hbm files for delete? i have even tried inverse=true and cascade=all-delete-orphan but doesnt help. Also, the each of these classes are entities by themselves. so cannot include the columns of child class as composite-elements.

any pointers will be much appreciated.

Thanks.
 
Vinay Binny
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you try cascade="all, delete-orphan"? Probably the syntax can also be cascade="all-delete-orphan". And let us know.

Vinay.
 
Kruti Bhan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinay, i have again tried all the 3 options i.e. cascade="all", cascade = "all-delete-orphan" and cascade="all,all-delete-orphan ". still doesn't work for me
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic