-->
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: Can This Data Model Even be Mapped with Hibernate?
PostPosted: Fri Jun 25, 2004 3:10 pm 
Newbie

Joined: Thu Jun 24, 2004 12:59 pm
Posts: 4
I'm trying to map to an existing datamodel for an older product we are migrating to Java.

I have tried ever way to map this collection over the last few days with no success.

Code:

-----------------------      ------------------------      -----------------------
|  Person             |      |  Phone_Nums          |      |   Business          |
-----------------------      ------------------------      -----------------------
|  Person_Id (PK)     |      |  Phone-Nums_Id (CK)  |      |   Business_Id (PK)  |
|  F_Name             |      |  Order (CK)          | ---- |   Name              |
|  L_Name             | ---- |  Number              |      |   Phone_Nums_Id (FK)|
|  AGE                |      |  Comment             |      -----------------------
|  Phone_Nums_Id (FK) |      ------------------------
-----------------------



Person and Business each have a collection of phone nums hanging off of them however there is no junction table. One part of a composite key (the Phone_Nums_Id) from the phone nums is referenced in the person and business tables.

To further complicate things, in the Person and Business tables, Phone_Nums_Id isn't technically a FK as in the relationship is not enforced in the test database I'm using.

I would like to construct Person and Business to have a collection of Phone_Nums on them however the mapping is eluding me. Using composite elements I am able to have hibernate properly build the query however it passes in the wrong search Criteria. For example for Person it passes in the Person_Id value instead of the Phone_Nums_Id on the record thus returning no or incorrect results.

Is what I'm attempting to do even possible or should I start the ball rolling on getting this more normalized, a task I'm not sure can be done?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 25, 2004 3:26 pm 
Newbie

Joined: Thu Jun 24, 2004 12:59 pm
Posts: 4
For reference, this is the mapping from Person that built the correct query but ended up passing in the wrong parameter:

Code:

<set name="phone_nums" table="Phone_Nums">
<key column="phone_nums_id" />
<composite-element class="com.bleh.PhoneNums">
<property name="number" type="string" column="NUMBER"/>
<property name="comment" type="string" column="COMMENT"/>
</composite-element>
</set>



Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 25, 2004 3:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate collections must use a PK as the target of a <key>. However, you never need to use collections. Just map two <many-to-one property-ref> associations and use queries instead of collections.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 25, 2004 3:43 pm 
Newbie

Joined: Thu Jun 24, 2004 12:59 pm
Posts: 4
Thanks. Response greatly appreciated.


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.