Hi folks,
I am having problems with a one-to-one relationship.
My tables are:
Customer(cust_id, cust_type)
Phone(phone_id, cust_id, phone_type)
My classes are:
Customer
PersonCustomer extends Customer
OrganizationCustomer extends Customer
Phone
MobilePhone extends Phone
ResidencialPhone extends Phone
my hibernate files are:
<class name="Customer" table="CUSTOMER" discriminator-value="C">
<id name="id" column="cust_id" unsaved-value="0">
<generator class="sequence"> <param name="sequence">customer_seq</param>
</generator>
</id>
<discriminator column="cust_type" type="character" />
<one-to-one name="residencialPhone" property-ref="customer" class="ResidencialPhone" />
<one-to-one name="mobilePhone" property-ref="customer" class="MobilePhone"/>
<subclass name="OrganizationCustomer" discriminator-value="J">
</subclass>
<subclass name="PersonCustomer" discriminator-value="F">
</subclass>
</class>
<class name="Phone" table="PHONE" discriminator-value="GEN">
<id name="id" column="phone_id" unsaved-value="0">
<generator class="sequence">
<param name="sequence">phone_seq</param>
</generator>
</id>
<discriminator column="phone_type" type="string" />
<many-to-one name="customer" column="cust_id" not-null="true" />
<subclass name="ResidencialPhone" discriminator-value="RES">
</subclass>
<subclass name="MobilePhone" discriminator-value="CEL">
</subclass>
</class>
My db relationship are one-to-many, because at the future I supposed that will have more types of phones than I have today. So the relationship is one-to-two today.
I just have one kind of phone for each customer, so (cust_id, phone_type) is a unique key.
Everything work well when I do a findBy... but when I do a merge I get a ClassCastException PersonCustomer
Is my relationship correct ? Can I do this ?
If so, Why the Exception ?
Thanks in advance...
|