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

269
Views
Primavera: Herencia JPA

Tengo un problema con la herencia de JPA en Spring.

Esta es la clase de usuario que hereda a la clase principal a continuación:

 @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;

Y esta es la clase de padres:

 @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;

Cuando agrego un objeto principal, el usuario todavía está vacío. ¿Por qué? ¿Cómo hago para que el usuario tenga el objeto principal mientras usa una identificación única? ¿Inserto Parent en User o Parent cuando agrego una instrucción SQL en mi archivo data.sql?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El tipo de herencia TABLE_PER_CLASS significa que cada entidad tiene todos sus datos, incluidas las propiedades heredadas, en tablas separadas. Entonces, cuando agrega un objeto de tipo Padre, todas las propiedades se almacenan en columnas en la tabla PADRE.

Si desea tener propiedades de la clase Usuario almacenadas en la tabla USUARIO y propiedades de la clase Padre almacenadas en la tabla PADRE, debe usar InheritanceType.JOINED. Las filas con los mismos ID se asignan a un objeto.

En el caso de la herencia, escriba TABLE_PER_CLASS cuando inserte Parent, sus instrucciones sql solo se insertan en la tabla PADRE, pero si cambia a JOINED, se debe insertar un objeto tanto en PADRE como en USUARIO.

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!