Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

271
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda