aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes JPA Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JPA Inheritance" Watch "JPA Inheritance" New topic
Author

JPA Inheritance

Morten Franorge
Ranch Hand

Joined: Jul 29, 2005
Posts: 137
I have a issue with implementing inheritance with a database design. The design is like this (somewhat simplified for readability)

PERSON
id INTEGER PK
name VARCHAR
type INTEGER FK (PERSON_TYPE.id)

PERSON_TYPE
id INTEGER PK
decode VARCHAR <--- This is the DISCRIMINATOR
created_by VARCHAR
created_at DATETIME

EMPLOYEE
id INTEGER
employee_no INTEGER
position VARCHAR

CUSTOMER
id INTEGER
customer_no INTEGER
vip CHAR

The relations is like this:
PERSON ---> PERSON_TYPE ---> EMPLOYEE/CUSTOMER

Is there anyway to solve this? The problem seems to be that the descriminator column is not in the parent class/table (person) but in a "codes table"


SCJP 1.4, SCBCD 1.3, SCBCD 5.0, SCEA J2EE, SCEA 5.0
Jon Wetherbee
author
Ranch Hand

Joined: Oct 05, 2006
Posts: 33
In your model, can you make PERSON a @MappedSuperclass instead of an @Entity? If so, you can have PERSON_TYPE be the root of the inheritance hierarchy, and it can be the entity that specifies the @DiscriminatorColumn.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JPA Inheritance