| Inheritance with multiple subclasses [message #629786] |
Wed, 29 September 2010 10:35  |
Omar Carvajal Messages: 4 Registered: September 2010 |
Junior Member |
|
|
Hey all,
I am trying to setup an entity that has more than one subclass with the inheritance type JOINED.
I have the following:
Person -> User
Person -> Employee
So basically I would have the person's common information in the person table and their corresponding user an employee information in separate tables.
I am having problems with it because the discriminator column does not let me have the same person for more than one table.
What is the best way to go about implementing this?
Thanks in advance,
Omar
|
|
|
| Re: Inheritance with multiple subclasses [message #629861 is a reply to message #629786] |
Wed, 29 September 2010 14:58   |
Chris Delahunt Messages: 863 Registered: July 2009 |
Senior Member |
|
|
Hello,
I'm not sure I follow what you are trying to do. You have 3 tables, but does that mean for every entry in the Person table you must have a corresponding entry in both the Employee and User tables? Or is it just that a User will have an entry in the user table and Person table, and an employee will have an entry in Employee and Person?
If it is the first, it doesn't sound like java inheritance at all. You just need 1 object type and map it over the 3 tables using the secondarytable annotation. If it is the second, map a Person entity/superclass to the Person table as shown here:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Inheritance #Annotations
If it is that the 3 are independent -ie a Person can have both a row in the User and Employee tables but doesn't have to, you might want to try something different such as mapping the User and Employee tables as their own entities and having the Person reference them with a 1:1 mapping.
Best Regards,
Chris
[Updated on: Wed, 29 September 2010 15:01] Report message to a moderator
|
|
|
|
| Re: Inheritance with multiple subclasses [message #630035 is a reply to message #629870] |
Thu, 30 September 2010 09:17  |
Chris Delahunt Messages: 863 Registered: July 2009 |
Senior Member |
|
|
Something along those lines for User anyway. Joined inheritance is just a very strict 1;1 - with Person/Employee it would allow Person to exist without an Employee row, but every Employee row would require a corresponding Person row. Using a relationship allows more flexibility but it can still be controled using foreign key constraints on the relationships (such as not null) and orphan removal in JPA to force a similar dependency if needed.
Best Regards,
Chris
|
|
|
Powered by
FUDForum. Page generated in 0.03163 seconds