-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping of Table with composite keys to a class
PostPosted: Fri Mar 19, 2004 5:11 am 
Newbie

Joined: Tue Mar 16, 2004 6:54 am
Posts: 4
I have three tables:

tbl_branchid
branch
description
email
branchHead

tbl_division
id
division
description
email
divisionHead

tbl_branchdivision
ui
branchId [ FK: tbl_branch(id) ]
divisionId [ FK: tbl_division(id) ]
manager
email


I have classes corresponding to tbl_branch and tbl_division

Problem:
What type of mapping stratergy must I use?
How will I design a class for the tbl_branchdivision table?

Please help!!!


Regards,
Jerry


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 19, 2004 5:15 am 
Newbie

Joined: Tue Mar 16, 2004 6:54 am
Posts: 4
I am sorry, there are some typo errors in the previous post!!!

I have three tables:

tbl_branch
id
branch
description
email
branchHead

tbl_division
id
division
description
email
divisionHead

tbl_branchdivision
id
branchId [ FK: tbl_branch(id) ]
divisionId [ FK: tbl_division(id) ]
manager
email


I have classes corresponding to tbl_branch and tbl_division

Problem:
What type of mapping stratergy must I use?
How will I design a class for the tbl_branchdivision table?

Please help!!!


Regards,
Jerry


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 19, 2004 6:00 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
something like...
<hibernate-mapping> <class name="branch" table="branch">
<id column="id" name="id">
<generator class="assigned"/>
</id>
<property column="description " name="description " />
.... more properties here
<bag name="divisions" table="branchdivision">
<key column="branchId"/>
<composite-element class="BranchDivision">
<property name="manager" />
<property name="email" />
<many-to-one column="divisionId " name="role" class="Division"/>
</composite-element>
</bag>
</class>
</hibernate-mapping>


map Division the simpliest way (no association) and BranchDivision with two many to one (one for Division, the other for branch)


It is just ONE example of mapping, you may optimize it....[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 19, 2004 6:28 am 
Newbie

Joined: Sun Feb 01, 2004 5:45 pm
Posts: 4
Or you can do this if you want to omit ID in Tbl_branchdivision:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
  <class name="net.Tbl_branch " table="tbl_branch">
    <id name="id" type="long" unsaved-value="0">
      <generator class="native"/>
    </id>
    <property name="branch " column="branch" type="string" length="255" not-null="true" unique="true"/>
    <property name="description " type="string" length="1024"/>
    <property name="email" column="email" type="string" length="255" />   
  </class>
 
   <class name="net.Tbl_division" table="tbl_division">
    <id name="id" type="long" unsaved-value="0">
      <generator class="native"/>
    </id>
    <property name="division" column="division" type="string" length="255" not-null="true" unique="true"/>
    <property name="description " type="string" length="1024"/>
    <property name="email " column="email" type="string" length="255"/>   
    <property name="divisionHead" column="divisionHead" type="string" length="255"/>   
  </class>

  <!-- many to many Tbl_division 2 Tbl_branch -->
  <class name="net.Tbl_branchdivision" table="Tbl_branchdivision">   
   <composite-id>
      <key-many-to-one name="branch" class="net.Tbl_branch" column="branchId"/>
      <key-many-to-one name="division" class="net.Tbl_division" column="divisionId"/>
    </composite-id>
    <property name="manager " type="string" length="255"/>
    <property name="email" type="string" length="255"/>
  </class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.