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