-->
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.  [ 2 posts ] 
Author Message
 Post subject: Understanding simple many-to-one relationship
PostPosted: Wed Jan 21, 2004 1:13 pm 
Beginner
Beginner

Joined: Tue Sep 23, 2003 5:00 pm
Posts: 40
Hi,

I have read the documentation several times but, there is something I still understand about many-to-one relationships and cascade update, save and delete.

On a simple example, imagine I have 2 classes:

Code:
public class City{
  Long id;
}

public class Team{
  Long id;
  City city;
}


The mapping should be :

Code:
<hibernate-mapping>
  <class name="City" table="city">
    <id name="id" column="city_id" unsaved-value="null">
      <generator class="hilo"/>
    </id>
  </class>
</hibernate-mapping>


<hibernate-mapping>
  <class name="Team" table="Team">
    <id name="id" column="team_id" unsaved-value="null">   
      <generator class="hilo"/>
    </id>
    <many-to-one name="city" class="City" column="city_id"/>
  </class>
</hibernate-mapping>


A team must belong to one and only one City but a City can have multiple teams.

Is the mapping above accurate ?

Unless I misread the documentation, we can't not specify cascade="delete" for this kind of many-to-one relationship ?

The solution seems to add the attribute List teams in the class City and to have a bidirectional relationships ...

I don't want to use collection mapping beteween City and Team because a lot of tables could reference City and I would like to add a new List attribute to the class City for each one.


Can anyone help to understand this ... and tell me the mistakes I wrote ?

Thanks in advance
sylvain_2020


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 1:48 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If you want to delete teams when a city is deleted wo having a the other side mapping, use the Lifecycle interface (not sure) or an interceptor

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.