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.