-->
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.  [ 1 post ] 
Author Message
 Post subject: Why do subclasses need to inherit parent primary keys?
PostPosted: Wed Aug 03, 2005 6:55 am 
Newbie

Joined: Tue Aug 02, 2005 12:23 pm
Posts: 1
Location: Dublin
Hello All,

I am migrating an existing datamodel and trying to map hibernate onto to schema. I have seen post whihch are related to this issue, but have not been given a reason why this can not be done. Can anyone help?

here is the encountered problem....

I have a relationship the is logically a subclass relationship (ie: user->agent user). But the schema defines a primary key column for each table and obviously a forign key column in the "agent user" to relate it back to the user table. So the agent user table has a Primary key to uniquely identify it (to other tables) AND a Foriegn Key to the users. I am aware that this is probaly not a clever design (especially for my needs) but it is in existance and I must try to use it.

Using XDoclet, my generated mapping files fails to pick up my primary key in the Agent User class and instead defaults the primary key to the user tables foriegn key (because of the sub-classe relationship). When I run my unit tests, the agent can not be persisted due to a not null constraint on the primary key column in the database. The generated SQL has ignored my tables primaray key and does not insert a value into it.

Hibernate (or xdoclet) has essentially ignored my declaration of a primary key definition for the Agent user object and used the parents class primary key. The mapping file has no record of my primary key?

It is not disirable to redifine the scema because we need to be backward compatible.

I am wondering why this is not supported in hiberrnate? or is it?

Hibernate version:
2.17

Mapping documents:
N/A

Xdoclet:
Here is my xdoclet declaration placed above my relavent setter for my primary key field...
/**
* @hibernate.id
* generator-class="sequence"
* type="long"
* column="AGENTID"
* @hibernate.generator-param
* name="sequence"
* value="MCS_AGENT_SEQ"
*
*/

Here is my xdoclet for the class declaration...
@hibernate.joined-subclass table="MCS_AGENT"
* @hibernate.joined-subclass-key column="PAYMENTUSERID"

and my code is something like....

public class Agent extends User .

I *DO NOT* want the joined-subclass-key column to be the primary key column in my new mapping, but this seems to be imnpossible


Full stack trace of any exception that occurs:
N/A

Name and version of the database you are using:
Oracle 9

The generated SQL (show_sql=true):
n/A

Debug level Hibernate log excerpt:
n/a


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

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.