【发布时间】:2020-02-17 18:35:33
【问题描述】:
我正在使用 Spring Boot Starter Data Jpa (2.1.9.RELEASE),我正在尝试映射此表:
CREATE TABLE `foo` (
`id` int(11) NOT NULL,
`woo` tinyint(4) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
Entity 映射如下:
@Entity
@Table(name = "foo")
public class Foo {
@Id
@Column(name = "id")
private Integer id;
@Column(name = "woo")
private Integer woo;
public Integer getId() {
return id;
}
public Integer getWoo() {
return woo;
}
}
当我启动应用程序时,我收到以下错误:
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [woo] in table [foo]; found [tinyint (Types#TINYINT)], but expecting [integer (Types#INTEGER)]
我的属性是:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql:///test
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=validate
我尝试使用 vanilla Jpa 和 Hibernate(不受 Spring 管理)进行相同的映射,并且效果很好。
谁能指出我正确的方向?
Here's a link to the maven project,以防有人想直接尝试。
【问题讨论】:
标签: java spring hibernate spring-boot jpa