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.  [ 1 post ] 
Author Message
 Post subject: SQL for Parent/Child relationship?
PostPosted: Wed Jul 12, 2006 12:07 pm 
Newbie

Joined: Tue Mar 28, 2006 7:49 am
Posts: 8
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.