Hi all this is my first attempt to use hibernate.
I have a class Contact that contains a class History. Those 2 classes must be serialized into two different tables CONTACTS and HISTORIES. The relationship between contact and history is one-to-one. In HISTORIES table there is a foreign key that point to Contact where the history record belongs to. My problem is how to define all this relationship in Contact.hbm.xml.
I’ll appreciate any help or hint.
Java classes:
----------------
Code:
public class Contact {
private int id;
private String fname;
private String lname;
private History history;
…
}
Code:
public class History {
private int id;
private String familyHistory;
private String personalHistory;
private Contact contact;
…
}
Hibernate mapping files
----------------------------
Code:
<hibernate-mapping package="gr.osmosis.paediatric.model">
<class name="Contact" table="CONTACTS">
<id name="id" column="ID">
<generator class="native"/>
</id>
<property name="fname" />
<property name="lname" />
<!-- here must add something to
define one-to-one relation to history -->
</class>
</ hibernate-mapping >
Code:
<hibernate-mapping package="gr.osmosis.paediatric.model">
<class name="History" table="HISTORIES">
<id name="id" column="ID">
<generator class="native" />
</id>
<property name="familyHistory" />
<property name="personalHistory" />
<many-to-one
name = "contact"
column = "CONTACT_ID"
unique="true"
not-null = "true" />
</class>
</hibernate-mapping>
Thanks in advanced
/stavros