Error executing DDL "create table in Spring Data JPA?

ぐ巨炮叔叔 提交于 2021-02-10 12:15:41

问题


I want to save some data coming from the request. for that, I created some entity classes. but why I et this exception?

Error executing DDL "create table body_datum (body_datum_id integer not null, key varchar(255), value varchar(255), value_type varchar(255), primary key (body_datum_id)) engine=InnoDB" via 

Here are my properties.

spring.datasource.url= jdbc:mysql://localhost:3306/loadtestdb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create

Here is my model classes.

@Data
@Entity
public class BodyDatum {

    @Id
    @GeneratedValue
    private Integer bodyDatumId;

    private String key;

    private String value;

    private String valueType;
}

Product class like this

@Data
@Entity
public class Product {

    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    private Long pId;
    private String productName;
    private int pQty;
    private int price;

    @ManyToOne
    @JoinColumn(name = "customer_id")
    private Customer customer;
}

In the database, the Product table has created.

Why get such an error?

Thanks.


回答1:


I think the attribute "key" is reserved word for SQL. Rename your attribute like that :

@Data
@Entity
public class BodyDatum {

    @Id
    @GeneratedValue
    private Integer bodyDatumId;

    private String bodyDatumkey;

    private String value;

    private String valueType;
}


来源:https://stackoverflow.com/questions/59788078/error-executing-ddl-create-table-in-spring-data-jpa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!