Error code:
Hibernate: create table course (id integer not null auto_increment, index integer, name varchar(255), primary key (id)) engine=InnoDB
Oct 12, 2021 4:31:05 PM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Error executing DDL "create table course (id integer not null auto_increment, index integer, name varchar(255), primary key (id)) engine=InnoDB" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table course (id integer not null auto_increment, index integer, name varchar(255), primary key (id)) engine=InnoDB" via JDBC Statement
...
Hibernate: create table student (id integer not null auto_increment, name varchar(255), primary key (id)) engine=InnoDB
...
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'integer, name varchar(255), primary key (id)) engine=InnoDB' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:762)
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:646)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
... 36 more
Finally, I found that the problem is that an attribute name of my Course
class is index, and this is a keyword in MySQL
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "course")
@ManagedBean(name = "course")
public class Course {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private Integer index;
@ManyToMany(mappedBy = "courseList")
private List<Student> studentList;
}
Just change the name of index
Summary: attribute names of entity classes should not be keywords in the database
Read More:
- How to Solve Error executing DDL in JPA
- When the database table field is set to self incrementing, use the entity class to insert or update the data to solve the error (Hibernate Framework)
- [Solved] java.sql.SQLException: Table ‘xxx.hibernate_sequence’ doesn’t exist
- [Solved] org.hibernate.exception.SQLGrammarException: could not extract ResultSet at org.hibernate.exception
- Microservice call exceptions: error feign.RetryableException: Read timed out executing POST http://xxx…….
- Executing Maven command error: Java_HOME is not defined correctly executing maven
- [Solved] Hibernate Error: java.lang.StackOverflowError at java.lang.Integer.toString(Integer.java:402)
- org.hibernate.exception.SQLGrammarException: could not extract ResultSet, Resolve MySQL 5.7.5 or above GROUP_BY is not supported
- Springboot thymeleaf Error: Exception processing template “table/dynamic_table”: Error resolving template [common]…
- [Solved] Hibernate Error: Row was updated or deleted by another transaction
- [Solved] JPA Create Sheet error at the First time: Cant DROP [xxx];check that column/key exists
- [Solved] seata Error: io.seata.rm.datasource.exec.LockConflictException: get global lock fail, xid:xxx, lockKeys:xxx
- [Solved] write javaBean error, fastjson version 1.2.76, class org.apache.flink.table.data.binary
- [Solved] Springboot project introduces Font library error: java.awt.fontformatexception: bad table, tag = XXXXXX
- org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying XXX
- [Solved] Java Run Error: For input string: “XXX”
- [Solved] Java XXX: unable to find topic engine in module path
- [Solved] ln: failed to create symbolic link ‘/usr/bin/java’: File exists
- How to Solve Springboot Upload Files Error: The field XXX exceeds its maximum permitted size of 1048576 bytes
- IDEA Create Web Project with maven Error: The desired archetype does not exista…