-->
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: Nested Component Mapping
PostPosted: Wed Jan 10, 2007 6:50 pm 
Beginner
Beginner

Joined: Fri Jul 28, 2006 12:01 pm
Posts: 21
Hibernate version: 3.1

Name and version of the database you are using: Oracle 10g

I am having trouble with mapping nested components.

I have a persistent class called "Request" This class has a component "Address" whose fields consist of the various pieces of an address (House Number, Street, City, State, Zip). I also have a persistent class "State" which maps to a database table holding the 50 states.

I don't know how to map a persistent class (State) inside of a component (Address) of another persistent class (Request)

Database structure

Request
Request_ID - Primary Key
House_Number
Street
City
State_ID - Foreign Key to State
Country
Zip

State
State_ID - Primary Key
State_Name
State_Abbreviation

The reason I wish to use Address as a component instead of mapping the individual fields is because I have other Addresses in other tables and don't want to replicate the same fields all over the place when they can be grouped nicely into a class.

mapping document so far

Code:
        <component
            name="address"
            class="Address">
            <property   name="addressNumber"
                        type="integer"
                        column="HOUSE_NO"/>
            <property   name="addressNumberSuffix"
                        type="string"
                        column="HOUSE_NO_SUFFIX"/>
            <property   name="streetDirection"
                        type="string"
                        column="STREET_DIR"/>
            <property   name="street"
                        type="string"
                        column="HOUSE"/>
            <property   name="streetSuffix"
                        type="string"
                        column="STREET_SUFFIX"/>
            <property   name="city"
                        type="string"
                        column="CITY"/>
            <property   name="zip"
                        type="string"
                        column="ZIP"/>
            <component  name="state"
                        class="State"/>
                        <property   name="stateID"
                                    type="integer"
                                    column="STATE_ID"/>
                        <property   name="stateName"
                                    type="string"/>
                        <property   name="stateAbbreviation"
                                    type="string"/>
        </component>


Is this correct? Or am I handling State incorrectly?


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.