-->
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: Help with Hibernate Mapping
PostPosted: Tue Aug 19, 2008 10:36 am 
Newbie

Joined: Mon Aug 18, 2008 2:24 pm
Posts: 8
I am new to Hibernate and I am trying to figure out how to create a mapping file based on the following:

Table A
id (primary key)
name
date

Table B
id(foreign key)
user_id (foreign key)
school_id (foreign key)

Basically, Table B primary key is a combination of all the foreign keys. And, it is used to figure out which item from Table A to view. Can someone please give me an example of how to map this file in a hibernate mapping file. Would I use a join or what?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 5:42 pm 
Newbie

Joined: Thu Aug 14, 2008 4:26 pm
Posts: 7
tablea.hbm.xml

<class name="tableA" table="TABLEA">
<id name="id" column="ID" >
<generator class="assigned"/>
</id>
<property name="name" column="NAME"/>
<property name="date" type="timestamp" column="DATE"/>
<set name="ID" lazy="false" inverse="false" >
<key column="ID" />
<one-to-many class="tableB" />
</set>
</class>

tableb.hbm.xml

<class name="tableB" table="TABLEB">
<composite-id >
<key-property name="id" column="ID" > </key-property>
<key-property name="user_id" column="USER_ID"></key-property>
<key-property name="school_id" column="SCHOOL_ID"></key-property>
</composite-id>
<property name="id" column="ID" insert="false" update="false" />
<property name="user_id" column="USER_ID" insert="false" update="false" />
<property name="school_id" column="SCHOOL_ID" insert="false" update="false" />
</class>

also, make the mappings for foriegn keys user_id and school_id in thier respective hbm.xml files.

I hope it helps !


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.