Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA Inheritance

 
Morten Franorge
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Jon Wetherbee
author
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic