-->
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: legacy tables many-to-many, can it be done in hibernate?
PostPosted: Wed Jul 12, 2006 7:30 am 
Newbie

Joined: Wed Jul 12, 2006 6:52 am
Posts: 1
I have legacy db that cannot be modified. I have the following tables

doctor
--------
PK: ID

individual
---------
PK: ID
Head_Address

individual_address
-----------------
PK: ID
PK: Type
PK: Ind


So I have a 1-1 relationship from doctor.ID to individual.ID, no problem, but I have a many-many relationship between individual.Head_Address and individual_address.ID. The problem I'm running into is when an address belongs to more than one individual. I need to figure out a way to define a many-to-many relationship in hibernate without creating an intermediate table or extra columns? I am using a bag in this example, but could use a map. Any help would be appreciated. So my mapping looks like

<class name="Insured" table="doctor">
<id name="id" column="id" type="string">
<generator class="native"/>
</id>


<bag name="addresses" table="individual" lazy="false">
<key column="ID" property-ref="headAddress" />
<one-to-many class="InsuredAddress" />

</set>

<join table="individual" fetch="select">
<key column="ID"/>
<property name="headAddress" column="Head_Address"/>
....
</join>
</class>

On the address side, the mapping looks like

<class name="Address" table="individual_address">
<composite-id name="addressKey" class="AddressKey">
<key-property name="id" column="ID" />
<key-property name="type" type="string" column="Type
<key-property name="ind" type="integer" column="Ind"/>
</composite-id>
....
</class


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.