-->
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: Joining tables, mapping
PostPosted: Wed Mar 08, 2006 5:18 pm 
Newbie

Joined: Wed Mar 08, 2006 5:08 pm
Posts: 1
Hibernate 3.0

I am involved in a project where the database, tables are already created. The tables I am dealing with currently include simple joins between two or three tables to gather data. I cannot change this fact.

Since I have existing data, which approach do I use? I have read and cannot figure this out:
Table per concrete class?
Table per class hierarchy?
Table per subclass?

So let say table per subclass. If I am joining on two tables. Lets say foo and baz. Where foo.id is a primary key and baz.id is the foreign key.

When I create my mappings, do I create two mappings? I cannot seem to find examples of this type of join.

Then if I create two mappings, and two classes to hold the data in, then do I issue a hql query that joins the tables?

If someone could give me some starter points here, I would certainly appreciate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 7:08 pm 
Beginner
Beginner

Joined: Thu Jun 30, 2005 5:07 am
Posts: 33
First, you do not need to create hql in order to create the join table.
the join table will be created from the xx.hbm.xml files for example:
in Foo.hbm.xml file write something like that:
<set
name="associatedBaz"
table="foo_baz"
lazy="false"
cascade="save-update"
sort="unsorted"
>

<key
column="Foo_ID"
>
</key>

<many-to-many
class="com.mycompan.Baz"
column="Baz_ID"
outer-join="auto"
/>

</set>

in Baz.hbm.xml write something like:
<set
name="supportedFoo"
table="foo_baz"
lazy="false"
inverse="true"
cascade="save-update"
sort="unsorted"
>

<key
column="baz_ID"
>
</key>

<many-to-many
class="com.mycompany.Foo"
column="foo_ID"
outer-join="auto"
/>

</set>


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.