Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
Spring: JPA Inheritance

I have a problem regarding JPA inheritance in Spring.

This is the User Class which inherits to the Parent Class below:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class User implements Persistable<String> {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private int id;
private String password;
private String username;
private String firstName;
private String lastName;
@Enumerated(EnumType.STRING)
private UserRole userRole;

And this is the Parent Class:

@Entity
public class Parent extends User{
private static final long serialVersionUID = 1L;

@NotNull
private String imgName;
@NotNull
private String location;
@NotNull
private String postcode;
@NotNull
private String streetName;

When I add a Parent object, User is still empty. Why? How do I make it so that User holds the parent object while using a unique ID? Do I insert Parent into User or Parent when adding an SQL statement in my data.sql?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Inheritance type TABLE_PER_CLASS means, that each entity has all its data, including inherited properties, in separate table. So when you add object of type Parent, all properties are stored in colums in table PARENT.

If you want to have properties from class User stored in table USER and properties from class Parent stored in table PARENT, you should use InheritanceType.JOINED. Rows with same ids are mapped to one object.

In case of inheritance type TABLE_PER_CLASS when you inserts Parent your sql statements insert into table PARENT only, but if you change to JOINED, one object should be inserted into both PARENT and USER.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!