-->
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.  [ 5 posts ] 
Author Message
 Post subject: delete question
PostPosted: Wed Oct 27, 2004 10:37 am 
Newbie

Joined: Fri Oct 08, 2004 5:29 am
Posts: 8
Let's say I have two classes, Resource and User and every resource has an owner (which is an instance of User). This can be easily done with a many-to-one association from Resource to User like this:

Code:
<hibernate-mapping>
  <class name="Resource" table="resources">
    <id [...]/>
    <many-to-one name="owner" class="User"
      cascade="none" not-null="true"/>
  </class>
</hibernate-mapping>

Now when it comes to deleting a user all resources that refer to that user have to be deleted manually. Otherwise the 'not-null' constraint gets violated and the database is broken.

So, can Hibernate somehow remove the resources automatically? That would require a 'cascade' that work the other way around and propagates the operation from User to Resource.

Any help would be appreciated.

Markus


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 11:26 am 
Regular
Regular

Joined: Tue Sep 28, 2004 6:34 pm
Posts: 50
define one-to-many from User to resources with cascade all|delete|all-delete-orphan|delete-orphan

Lukasz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 11:45 am 
Newbie

Joined: Fri Oct 08, 2004 5:29 am
Posts: 8
Thanks for the answer. But I think one-to-many is used for Collection Mapping and cannot be used for this purpose. Am I wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 12:09 pm 
Regular
Regular

Joined: Tue Sep 28, 2004 6:34 pm
Posts: 50
User can have many Resources - isn't it a Collection (Set)?

Code:
  <set name="resources" lazy="true" inverse="true">
      <key column="user_id"/>
      <one-to-many class="Resource"/>
  </set>


Lukasz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 12:28 pm 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
yes, but the use case here was that a resource has 1 owner. it's obviously the use case for this particular system.

take a look at 6.8. Bidirectional Associations


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

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.