-->
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: Mapping a class hierarchy to multiple tables
PostPosted: Sun Oct 11, 2009 7:51 am 
Newbie

Joined: Mon Aug 24, 2009 3:46 pm
Posts: 2
Hello,

I ran into a problem with Hibernate 3.3.2 GA regarding the mapping of a class hierarchy to multiple tables. This is what I want to do:

I have one class "employee" and a derived class "manager". This simple class hierarchy shall be mapped to the table "t_employee" with the following mapping:

Code:
<class name="employee" table="t_employee">
...
  <subclass name="manager" >
   ...
</class>


In addition I want to be able to save instances of these classes to a second table "t_employee_hist". Since I cannot map a classname more than once I use entity names and changed the mappings like this:

Code:
<class name="employee" table="t_employee" entity-name="EMPLOYEE">
...
  <subclass name="manager" entity-name="MANAGER">
   ...

<class name="employee" table="t_employee_hist" entity-name="EMPLOYEE_HIST">
...
  <subclass name="manager" entity-name="MANAGER_HIST">
   ...


I have to use the entityname attribute with the subclass mappings as well to avoid mapping errors. Now I want to be able to save an employee, regardless if it is an employee or a manager, with: session.save("EMPLOYEE", empl) or session.save("EMPLOYEE_HIST", empl)

My problem is that this only works with real employee instances. When trying to save instances of the derived manager class I get an exception that the entity mapping cannot be found. It works, however, when I call "save" with the entity name I used with the sublass mapping for the manager class.

Of course I don't want to check the actual class of the objects I save. After all, this is what I use Hibernate for.

The odd thing is, this used to work with previous versions. But when we switched to the new version we received the aforementioned exception.

So my question is, if this is a bug with the recent version of hibernate or if I do something wrong?

Karl.


Top
 Profile  
 
 Post subject: Re: Mapping a class hierarchy to multiple tables
PostPosted: Sun Oct 11, 2009 5:25 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi k.basso,

could it be possible that you lack of a discriminator column for Hibernate to distinguish different entities of the same class hierarchy within the same table?

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: Mapping a class hierarchy to multiple tables
PostPosted: Mon Oct 12, 2009 3:08 pm 
Newbie

Joined: Mon Aug 24, 2009 3:46 pm
Posts: 2
Froestel wrote:
Hi k.basso,

could it be possible that you lack of a discriminator column for Hibernate to distinguish different entities of the same class hierarchy within the same table?

CU
Froestel


No, I just left it out in my example mapping code. As I said, it used to work flawlessly with previous Hibernate versions. It seems to be a change with the entity resolver or something.

I just can't believe that this is a bug because I suppose more people would have noticed it.


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.