Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Inheritance with multiple subclasses
Inheritance with multiple subclasses [message #629786] Wed, 29 September 2010 10:35 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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] by Moderator

Re: Inheritance with multiple subclasses [message #629870 is a reply to message #629861] Wed, 29 September 2010 15:31 Go to previous messageGo to next message
Eclipse UserFriend
Chris,

Thanks for your response.

To clear things up, I do need there to be records in Employee and User for the same Person.

That is, I could have an Employee that does not have a login, so he does not have a record in User. Or I could have an Employee that does have a login so I'd need records in both entities.

For this scenario, you recommend a OneToOne mapping to the Person entity?

Cheers,

Omar
Re: Inheritance with multiple subclasses [message #630035 is a reply to message #629870] Thu, 30 September 2010 09:17 Go to previous message
Eclipse UserFriend
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
Previous Topic:columnDefinition="RAW()" x hextoraw
Next Topic:Data Soruce in websphere is not working
Goto Forum:
  


Current Time: Wed Jul 23 15:47:47 EDT 2025

Powered by FUDForum. Page generated in 0.07771 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top