-->
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 & Inheritance
PostPosted: Thu Jul 08, 2004 4:58 am 
Newbie

Joined: Wed Jun 16, 2004 9:12 am
Posts: 9
Hi,
I was wondering if it is possible to tell Hibernate how to deal with cascade delete and inheritance. Well, let me explain the situation. I have implemented the classes and the according mapping for the following outcut of an ER diagram.

Image

The entity type "AbstractResource" has the following attributes:
- ID
- Title

This ET is supposed to abstract from all the resources from which I don't have all the information I need to store it as a concrete "Resource" like "Book" or "Serial". Though there is a lack of information, I'd like to keep it in the database since it is possible to name such a resource as a referencing one for another concrete resource.

The relationship should express this circumstance. Concrete "Resources" can be referenced either by (other) concrete "Resources" or by "AbstractResource".

When it comes to deletion of a concrete resource I want to distinguish between referencing concrete resources and referencing abstract resources.

Let's consider the following situation:

Book A which is a concrete resource is referenced by AbstractResource X.
As soon as I delete Book A I want Hibernate to delete AbstractResourceX as well, because in my scenario it does not make sense to keep it in the database.

Whilst:

Book A is again a concrete resource and is referenced by Book B which is another concrete resource. In this case I don't want Hibernate to cascade the deletion to the child class.

Right now I can either delete all the referencing resources, no matter if it is an abstract or a concrete one, or just delete the resource that is supposed to be deleted anyway.

I hope the following excerpt of the mapping file is sufficient:

Code:
<class name="AbstractResource" table="abstractresource">
   
   <id name="id" column="ResourceID" type="java.lang.Long">
      <generator class="native"/>
   </id>   
   
   <property name="title" column="Title"/>
   
   <set name="referencedBy" table="containedin" cascade="save-update" inverse="false">
      <key column="ResourceID2"/>
      <many-to-many column="ResourceID" class="AbstractResource"/>      
   </set>
        <joined-subclass name="Resource" table="resource">
      <set name="containedIn" table="containedin" cascade="save-update" inverse="false">
         <key column="ResourceID"/>
         <many-to-many column="ResourceID2" class="AbstractResource"/>      
      </set>

        [...]



Is there any way to tell Hibernate to act in the way described above?

Lots of thanks in advance,
Florian


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.