在Spring Data JPA中执行DDL"创建表时出错? [英] Error executing DDL "create table in Spring Data JPA?

查看:289
本文介绍了在Spring Data JPA中执行DDL"创建表时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存一些来自请求的数据.为此,我创建了一些实体类.但是为什么我会看到这个例外?

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 

这是我的财产.

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

这是我的模型课.

@Data
@Entity
public class BodyDatum {

    @Id
    @GeneratedValue
    private Integer bodyDatumId;

    private String key;

    private String value;

    private String valueType;
}

此类产品

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

在数据库中,已经创建了Product表.

In the database, the Product table has created.

为什么会出现这样的错误?

Why get such an error?

谢谢.

推荐答案

我认为属性"key"是SQL的保留字.像这样重命名您的属性:

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

这篇关于在Spring Data JPA中执行DDL"创建表时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆