-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: one-to-one
PostPosted: Fri Sep 23, 2005 12:00 pm 
Newbie

Joined: Fri Sep 23, 2005 11:41 am
Posts: 1
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...


Top
 Profile  
 
 Post subject: restrictions on one to one
PostPosted: Fri Sep 23, 2005 11:53 pm 
Newbie

Joined: Fri Sep 23, 2005 11:32 pm
Posts: 1
in my view of hibernate now you can not has two one-to-one relationship from one entity to the other, for, how can it know which type you really refer to.hense the ClassCastException occurred.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.