Hibernate version: 3.1.2
Mapping documents:
Code:
<!-- In Parent's mapping file -->
<set name="childset" table="children" lazy="false" cascade="all" inverse="true">
<key column="PARENT_ID"/>
<one-to-many class="org.example.Child"/>
</set>
Code:
<!-- In Child's mapping file -->
<many-to-one
name="parent"
class="org.example.Parent"
column="PARENT_ID"
not-null="true" />
Name and version of the database you are using: MySQL 4.1.18
Hi,
I've read all the Hibernate doc's on parent/child relationships (Chapters 16 and 21 of the Docs and
http://www.hibernate.org/209.html), and think I understand all of the mappings and what's required (and why).
However, one thing that is not discussed is how the database tables under this are configured.
So, can someone supply an example of the SQL to create the tables for this? Is it as easy as:
Code:
CREATE TABLE parents (
PARENT_ID INT unsigned NOT NULL primary key,
);
CREATE TABLE children (
CHILD_ID INT unsigned NOT NULL primary key,
PARENT_ID INT unsigned NOT NULL
);
Is this all I have to do to create the tables correctly?
I'm a bit confused as to how the parent table keeps a track of the children it has (or does hibernate do this for us?).
Again, many thanks. Sorry if this question is stupid.
Ed.