[英]I used Spring Data JPA to create a table in MySQL, but the creation failed
我使用Spring Data JPA在MySQL中创建一个表,但是创建失败。 我在实体类中找不到错误,并且我认为配置没有错。
我更改了属性中的某些jdbc连接语句以及实体类上的注释,但没有用。
@Data
@Entity
@Table
public class User {
@Id
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String id;
@Column(unique = true)
private String userName;
@Column
private String password;
}
属性文件如下:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/blog?characterEncoding=utf8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=localhost # Spring Data Jpa
spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true
最佳做法是, id
始终应为Long
类型。 请更改它,它应该可以工作。
我不知道如何自动增加String ,最好将其更改为Long或int 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.