Hi All,
Until now, I mapped all with entityes. For example I mapped a Address of a Person as a Entity. I have read about components, and I think that Address information has to be mapped as components, no as Entyties. However, I don't know How I Can I map this situation:
As you can see, Addresses (BankAddress and ContactAddress) in database are "created" as generalitation tables, and in my code I have a Address Class and Bank_Address and Contact_Adrress which inherited from Address class.
For the moment, I've mapped as follow:
Customer-->
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:hiberna...">
<class name="Model.Customer" table="CUSTOMER">
<id name="Id" column="ID" type="String">
<generator class="assigned" />
</id>
<component class="Model.Name" name="Name">
<property name="First_name" column="FIRST_NAME" type="String"/>
<property name="Second_name" column="SECOND_NAME" type="String"/>
</component>
<component class="Model.BankAddress" name="Bank_address"/>
<set name="Contacts" table="CONTACT_ADDRESS">
<key foreign-key="CUSTOMER_ID"/>
<composite-element class="Model.ContactAddress"/>
</set>
</class>
</hibernate-mapping>
Addressess-->
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:hiber...">
<class name="Model.Address" table="ADDRESS">
<id name="Id" column="ID" type="String">
<generator class="assigned" />
</id>
<property name="Street" type="String" column="STREET"/>
<property name="Number_street" type="String" column="NUMBER_STREET"/>
<property name="City" type="String" column="CITY"/>
<property name="State" type="String" column="STATE"/>
<joined-subclass name="Model.BankAddress" table="BANK_ADDRESS">
<key column="ADDRESS_ID"/>
<property name="BankName" type="String" column="BANK_NAME"/>
<property name="Account" type="String" column="ACCOUNT"/>
</joined-subclass>
<joined-subclass name="Model.ContactAddress" table="CONTACT_ADDRESS">
<key column="ADDRESS_ID"/>
<component class="Model.Name" name="ContactName">
<property name="First_name" column="FIRST_NAME" type="String"/>
<property name="Second_name" column="SECOND_NAME" type="String"/>
</component>
<property name="Phone" type="String" column="PHONE"/>
</joined-subclass>
</class>
</hibernate-mapping>
In this situation I'm forced to map addressess as entity asociations (one-to-one, and one-to-many / many-to-one)?