-->
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.  [ 3 posts ] 
Author Message
 Post subject: WrongClassException and aspect/profil object design
PostPosted: Sun Oct 23, 2005 8:49 pm 
Newbie

Joined: Tue May 17, 2005 8:46 pm
Posts: 4
Hibernate version:
Hibernate 3.0

Name and version of the database you are using:
Postgre SQL 8.0

Hi all,
I have some difficulties to design a object structure with hibernate.
I looked for s solution of my pb in the forum but i didn't find it, so I decid to

My problem is :
I have:
a User class
a Doctor class extends User class
a Patient class extends User class

so I use joined tables structure in my DB.
So with hibernate. the simpled hibernate mapping is :

<class name="User" table="user>

<joined-class name="Doctor" table="doctor">
<key column="id">

<patient properties ... />

</joined-class>

<joined-class name="Patient" table="patient">
<key column="id">

<doctor properties ... />
</joined-class>

</class>

The pb is that a doctor can be a patient as well. Doctor and Patient are just some "aspects" or profil of the same user.
so sometime i would like switch to the Doctor Class to the Patient class, but Hibernate did a WrongClassException because for the program, it's either a doctor or a patient, he can be the same object.. I don't known how resolve this problem because Apparently it's not possible to do:
session.get(Doctor.class, id);
and after
session.get(Patient.class, id);
-> wrongClassException


Can you help me please ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 9:58 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
are you sure session.get is throwing the exception? If so, print the stack trace. also, do not be suprised at anything hibernate does if you are using a Session after an exception is thrown. once you get an exception you should close it and throw it away.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 10:11 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
also, take a look at those inheritance options that are available that don't use discriminators ...

http://www.hibernate.org/hib_docs/v3/re ... strategies


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.