I have 2 tables: countries and cities
country has an id(PK)
city has an id(PK) and a country(FK)
I use these mappings, but the foreign key isn't created in de db.
What do I do wrong?
Code:
<class name="data.Country" table="countries">
<id name="id" column="id" length="31">
<generator class="assigned" />
</id>
</class>
<class name="data.City" table="cities">
<id name="id" column="id" length="31">
<generator class="assigned" />
</id>
<one-to-one name="country" class="data.Country" />
</class>
And how do these relations work?
This is how I understand it:
one-to-one, one city has one country
one-to-many, one city has multiple countries
many-to-one, multiple cities can have the same country
many-to-many, multiple cities can have multiple countries
If I understand it right, country should have an one-to-many to cities and city should have an one-to-one to countries.
This doesn't make sence to me.
In SQL without hibernate I would give city a FK to country and problem solved.
Then the right query could get every combination.