Hibernate version:3.2
Name and version of the database you are using:Oracle 10g
I have been playing around with the different inheritance mapping strategies outlined in the "Java Persistence with Hibernate" book by Christian Baur and Gavin King, but I am still a little confused about the best strategy for my particular situation. I have tried searching the forum, but can't seem to find a good issue to latch on to.
If have 3 classes:
Code:
public class Person
{
set/getName();
}
public class Employee extends Person
{
set/getEmployer();
}
public class User extends Person
{
set/getRole();
}
These are (obviously) severely simplified examples of my actual classes. In my system, an instance of Person can be created (not exist as an Employee or a User) and that Person can be a User, an Employee, or all three (every User and Employee is a Person).
Requirements:
1. I need to be able to insert a Person object and later "upgrade" that Person to a User, an Employee, or both. To further clarify, I need the object to be a Person, Employee, and User at the same time (e.g. if i query for Person, i get Person record; if i query for Employee, i get the Employee record; if i query for User, I get the User record). I also need to be able to "downgrade" them to just a Person. I was having problems with this when employing the table/subclass strategy.
2. When querying for Person, I want 1 row if the Person is a User AND and Employee (the 1 row should be just Person)... basically, when querying Person, I am content to only receive Person objects (even if that Person is just an Employee and not a User).
3. When updating the data for an Employee, I want the Person data to be updated for Person and User (this makes me think table/subclass is best... but, I think number 1 fails). And, of course, changes in User or Person are reflected in the other 2 objects as well.
I appreciate any advice you can provide. If any clarification is needed, please let me know.
Thanks,
Paul