-->
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: problem on "table per class hierarchy" handling in
PostPosted: Wed Dec 08, 2004 11:23 pm 
Newbie

Joined: Wed Dec 08, 2004 10:35 pm
Posts: 7
Hello,

I am a new hibernate guy, could someone help me about the following peoblem.

I have two tables, I am going to handling the inheritance with " table per class hierarchy"

two tables:
Users UserTypes
--------------------------- ----------------------------
UserID (PK, int) |-----------> UserTypeID(PK, int)
UserTypeID (FK, int) <---------| ....
...
--------------------------- ---------------------------

Subclass of Users:
Doctors when UserTupeID = 1
Patients when UserTypeID = 2

When I do mapping, I have following classes

class Users {
int userid;
UserType usertype;
---
}

class Doctors extends Users{ }
class Patients extends Users{ }

class UserType{
int usertypeid;
...
}

The mapping file:

<hibernat-mapping>
<class name="Users" table="users">
<id name="userid" column="UserID" type="java.lang.Integer">
<generator class="native" />
</id>

## <discriminator column="UserTypeID" type="java.lang.Integer" />
<property .... />

## <many-to-one name="usertypes" column="UserTypeID"/>

<subclass name="Doctors" discriminator-value="1" />
<subclass name="Patients" discriminator-value="2" />
</class>

<class name="UserTypes" table="usertypes">
<id name="usertypeid" column="UserTypeID"
type="java.lang.Integer">
<generator class="native" />
</id>
<property .... />
</class>
</hibernate-mapping>

I think the ## parts in the upper mapping file are not correct, becuase I duplicate the column "UserTypeID", but I have no idea how to handle that, can someone help me.

Thanks a lot
[/code][/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 09, 2004 3:37 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
change

Code:
## <discriminator column="UserTypeID" type="java.lang.Integer" />
<property .... />

## <many-to-one name="usertypes" column="UserTypeID"/>


to
Code:
<discriminator column="UserTypeID" type="java.lang.Integer" />
<property .... />

<many-to-one name="usertypes" insert="false" update="false" column="UserTypeID"/>


next time use code tag

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 09, 2004 10:02 am 
Newbie

Joined: Wed Dec 08, 2004 10:35 pm
Posts: 7
Quote:
Thanks a lot !!!
Yang_bin


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.