I have the object Laboratory and ProductionCenter.
The laboratory have 2 CoordinateModel and the production center 1.
Code:
class Laboratory {
CoordinateModel shippingAddress;
CoordinateModel invoicingAddress;
}
class ProductionCenter {
CoordinateModel address;
}
class CoordinateModel {
String address;
String city;
}
I want to be able to share the CoordinateModel between Laboratory and ProductionCenter. I don't want to have 2 addresses on the ProductionCenter, so I don't want to use inheritance.
How can I configure my mapping for the laboratory and address to be able do what I want?
I have tried this:
Code:
<hibernate-mapping>
<hibernate-mapping>
<class name="dti.xmscore.model.cCoordinateModel" table="contact">
<id name="id" column="contact_id" type="long" unsaved-value="0">
<generator class="hilo"/>
</id>
<property name="aStreet" column="street" type="string" length="30"/>
<property name="aCity" column="city" type="string" length="30"/>
</class>
</hibernate-mapping>
And the mapping for the cLaboratory:
Code:
<hibernate-mapping>
<class name="dti.xmscore.model.cLaboratory" table="lab">
<id name="aNewLabID" column="lab_id" type="string" length="20" unsaved-value="null">
<generator class="assigned"/>
</id>
<property name="aManagerName" column="manager_name" type="string" length="30"/>
<one-to-one name="aShippingContact" class="dti.xmscore.model.cCoordinateModel" cascade="all" constrained="true"/>
</class>
</hibernate-mapping>
When I generate my DB, no column is added to the cLaboratory to contains the CoordinateModel. When I run the code, the contact I added to the DB, but for sure, no contact_id is added to the laboratory.
Here is my code to store the Laboratory:
Code:
cLaboratory lab = new cLaboratory("lab200000240");
cCoordinateModel lContact = cCoordinateModel("1000 street", "city");
lab.setaShippingContact(lContact);
Thanks