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: Component Mapping with Similar Sets of Fields - Possible?
PostPosted: Fri Aug 18, 2006 4:07 pm 
Newbie

Joined: Mon Jul 18, 2005 10:15 am
Posts: 17
I have a PERSON table structure, which I am unable to change, which has three sets of phone number fields

HOME_PHONE_AREA_CODE
HOME_PHONE_SWITCH
HOME_PHONE_LINE_NUMBER

CELL_PHONE_AREA_CODE
CELL_PHONE_SWITCH
CELL_PHONE_LINE_NUMBER

WORK_PHONE_AREA_CODE
WORK_PHONE_SWITCH
WORK_PHONE_LINE_NUMBER

I want to use Component mapping in Hibernate. How can I map the table so that I can generate a Person class like this
public class Person {
...
private Phone homePhone;
private Phone cellPhone;
private Phone workPhone;
...
}


Is it possible in Hibernate 3.x?


Hibernate version:
3.1.3

TIA
/JB


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 5:37 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Code:
public class Phone {
...
   private String area;
   private String switch;
   private String number;
...
}

Code:
<class name="Person " table="PERSON">
...
   <component name="homePhone" class="Phone">
      <property name="area" column="HOME_PHONE_AREA_CODE"/>
      <property name="switch" column="HOME_PHONE_SWITCH"/>
      <property name="number" column="HOME_PHONE_LINE_NUMBER"/>
   </component>
   <component name="cellPhone" class="Phone">
      <property name="area" column="CELL_PHONE_AREA_CODE"/>
      <property name="switch" column="CELL_PHONE_SWITCH"/>
      <property name="number" column="CELL_PHONE_LINE_NUMBER"/>
   </component>
   <component name="workPhone" class="Phone">
      <property name="area" column="WORK_PHONE_AREA_CODE"/>
      <property name="switch" column="WORK_PHONE_SWITCH"/>
      <property name="number" column="WORK_PHONE_LINE_NUMBER"/>
   </component>
...
</class>


Please, don't forget to rate.


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.