I have 2 example classes below that are linked by a one-to-one or a many-to-one (would like to know if its possible for both).
I just want to know is it possible to leave out
personId from my
hair class and just have it referenced in the mapping (somewhat in a way of a discriminator). I don't think the hair object should care who it is attached to, it should just know about itself.
Java
Code:
class Person {
String personId;
Hair hair;
}
class Hair {
String personId;
String color;
String type;
}
Hibernate
Code:
<class name="Person" table="PersonTable">
<id name="personId" column="ID" type="string" />
<one-to-one name="hair" entity-name="Hair"/>
</class>
<class name="Hair" table="HairTable" entity-name="Hair">
<id name="personId" column="ID" type="string" />
<property name="color" column="COLOR" type="string" />
<property name="type" column="TYPE" type="string" />
</class>