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?