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

660
Views
Hibernate tratando de alterar la tabla antes de crearla

Problema simple aquí: estoy ejecutando Spring Boot 2.2.5 en una base de datos mySQL con MySQL5Dialect. Todo iba bien hasta que agregué la anotación @ManyToOne a la entidad Diapositiva que hace referencia a la entidad Usuario; ahora Hibernate no puede crear tablas porque crea la tabla de usuarios y luego intenta modificar la tabla de diapositivas que aún no ha creado. ¿Qué hice mal?

Usuario:

 @Entity @Getter @Setter @NoArgsConstructor @AllArgsConstructor @ToString @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private boolean enabled; private String token; private String username; private String password; private String role; private String name; private String surname; private String email; private boolean emailVisible; private String phone; private boolean phoneVisible; private int cohortNumber; private String company; private String position; private String linkedIn; private String function; private String bio; private String membership; private Date membershipSince; private Date membershipUntil; }

Deslizar:

 @Entity @Getter @Setter @NoArgsConstructor @AllArgsConstructor @ToString(exclude = "editor") @Table(name = "slides") public class Slide { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private boolean visible; private int order; private Date edited; @ManyToOne @JoinColumn(name = "editor_id") private User editor; private String title; private String text; private String picture; }

Detalles de configuración de Hibernate:

 spring.jpa.hibernate.ddl-auto = update spring.datasource.initialization-mode=always spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

Y el error:

 Hibernate: create table users (id integer not null auto_increment, bio varchar(255), cohort_number integer not null, company varchar(255), email varchar(255), email_visible bit not null, enabled bit not null, function varchar(255), linked_in varchar(255), membership varchar(255), membership_since datetime, membership_until datetime, name varchar(255), password varchar(255), phone varchar(255), phone_visible bit not null, position varchar(255), role varchar(255), surname varchar(255), token varchar(255), username varchar(255), primary key (id)) engine=MyISAM Hibernate: alter table slides add constraint FKobqxptfxg36ls278o63ouq369 foreign key (editor_id) references users (id) 2020-08-11 14:27:48.201 WARN 8224 --- [ restartedMain] ohtsiExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL "alter table slides add constraint FKobqxptfxg36ls278o63ouq369 foreign key (editor_id) references users (id)" via JDBC Statement ... Caused by: java.sql.SQLSyntaxErrorException: Table '32293814_alumnicemba.slides' doesn't exist
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Encontré el problema:

private int order;

"ordenar" no está permitido como nombre de campo aquí e Hibernate estaba encontrando un error al intentar crear la tabla de diapositivas pero no registrando ese error. Cambié el nombre del campo a "ordenar" y ahora funciona.

over 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!