• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA Inheritance

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
 
author
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic