I got an error
When I created an order
table, just like …
application.yml
spring: datasource: username: ${database.username} password: ${database.password} url: jdbc:mysql://${database.host}:3306/${database.name}?characterEncoding=utf-8&useUnicode=true&useSSL=false&rewriteBatchedStatements=TRUE jpa: database: MYSQL hibernate.ddl-auto: update show-sql: true database-platform: com.example.springtransactionisolation.config.MySQL5InnoDBDialectUtf8mb4 properties.hibernate.jdbc.batch_size: 100 properties.hibernate.show_sql: ${spring.jpa.show-sql} properties.hibernate.format_sql: ${spring.jpa.show-sql}
logging.level.org.hibernate.SQL: debug logging.level.org.hibernate.type: trace
|
entity
@Data @Entity @NoArgsConstructor @Table(name = "order") public class Order {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) private Long id;
@Enumerated(EnumType.STRING) @Column(name = "order_status", nullable = false) private OrderStatus orderStatus;
@Column(name = "update_date", nullable = false) private LocalDate updateDate;
}
|
Sql syntax log
2019-02-27 16:30:57.626 WARN 73285 --- [ main] o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL " create table order ( id bigint not null auto_increment, order_status varchar(255) not null, update_date date not null, primary key (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;" via JDBC Statement
|
Soluation
Because the sql table order
is a reserved word in MySQL so that hibernate sql syntax executed error.
So I renamed the order
entity to order_form
…
@Data @Entity @NoArgsConstructor @Table(name = "order_form") public class OrderForm {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) private Long id;
@Enumerated(EnumType.STRING) @Column(name = "order_status", nullable = false) private OrderStatus orderStatus;
@Column(name = "update_date", nullable = false) private LocalDate updateDate;
}
|
在命名 table 或 column 的時候真的不能太隨便啊…
Ref