I have a class hierarchy that looks like this:
Code:
Person
----------|---------
| |
Employee Customer
|
Manager
The database has one table for each class and each table contains the following data:
Code:
PERSON PERSON_ID NAME
1 Bob
2 Sally
3 Mike
4 Peter
5 Andy
EMPLOYEE EMPLOYEE_ID HIRE_DATE
2 02/02/02
3 03/03/03
4 04/04/04
MANAGER MANAGER_ID TITLE
4 Department Manager
CUSTOMER CUSTOMER_ID CUSTOMER_SINCE
2 01/01/01
5 01/01/02
From this we can read that: Bob is just a person, Sally is a employee and a customer, Mike is a employee, Peter is a an employee and a manager, and Andy is a just a customer.
I'm using the following structure to map the inheritance:
Code:
<class name="Person" ...
<joined-subclass name="Customer" ...
<joined-subclass name="Employee" ...
<joined-subclass name="Manager" ...
Now to the problem. If I call SessionImpl.get() passing it Employee.class and the identifier 1 then I will get an instance of Employee back. However, if I pass it the same class and 2 I get an instance of Customer back. Likewise, passing Person.class and 3 I'll get an Employee instance back.
What puzzles me is that I'm specifically asking for an Emplyee instance, yet Hibernate seems to do a little extra and bring me the sub-class. Why is this and is there a way to disable this behavior? The class for each type has some behind-the-scenes logic (an alternative data representation) that is different depending on what kind of object is being instantiated and I must be able to get exactly what I ask for (i.e. casting to the class I asked for is not an option due to the data structure backing the instance).
Any help is greatly appreciated!
Thanks,
-Kaare