问题
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