-->
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: Many-to-one mapping question on updates
PostPosted: Tue Nov 11, 2003 7:34 pm 
Beginner
Beginner

Joined: Thu Nov 06, 2003 10:04 pm
Posts: 22
I have a 1-1 relation between two classes, ManageableEvent and Location, with ManageableEvent containing Location. The mapping is like this.

Code:
<class name="ManageableEvent" table="manageable_events">

    <id name="id" type="UUID">
          <column name="manageble_event_id" sql-type="char(36)"/>
          <generator class="UUIDGenerator"/>
    </id>

    <many-to-one class="Location" name="location" cascade="all">
          <column name="location_id" sql-type="char(36)"/>
    </many-to-one>

</class>

<class name="Location" table="locations">

    <id name="id" type="UUID">
          <column name="location_id" sql-type="char(36)"/>
          <generator class="UUIDGenerator"/>
    </id>

</class>



I have a ManageableEvent object with a Location object contained in it. When I save it, one row is created in manageable_events table with a location_id value that corresponds to one row in the locations table.

Now in some other tier, I replace the Location instance contained in teh ManageableEvent to some other new Location object. Now if I save this ManageableEvent, the row in manageable_events table is updated with the new location_id that corersponds to the new row in the locations table.

My question is what happens to the old Location entry in the locations table that was related to the ManageableEvent before. Do I have to explicitly delete that row or is there some way in the mapping that I can take care of deleting that "orphaned" row in the locations table.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 7:54 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
I suppose cascade="all-delete-orphans" is just for this. Although I'm not sure :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 8:01 pm 
Beginner
Beginner

Joined: Thu Nov 06, 2003 10:04 pm
Posts: 22
An error occurs on parsing the mapping file with cascade set to "all-delete-orphan" in a many-to-one mapping


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 8:07 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Ah.. It seems it is for one-to-many only.
Then you have to delete manually.

7.7.1. Lifecycle objects
"A child which becomes unreferenced by its parent is not automatically deleted, ..."


Top
 Profile  
 
 Post subject: Re: Many-to-one mapping question on updates
PostPosted: Wed Nov 12, 2003 8:42 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
rcasturi wrote:
My question is what happens to the old Location entry in the locations table that was related to the ManageableEvent before. Do I have to explicitly delete that row or is there some way in the mapping that I can take care of deleting that "orphaned" row in the locations table.


Sounds like a one-to-one mapping, not a many-to-one.

_________________
Emmanuel


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.