spring boot版本: 2.0.6.RELEASE
Spring cloud版本: Finchley.SR2
使用Spring boot 2.0 + JPA + H2,配置如下
spring:
jpa:
generate-ddl: false
show-sql: true
hibernate:
ddl-auto: none
datasource:
schema: classpath:schema.sql
data: classpath:data.sql
platform: h2
为了接入eureka注册中心,加入了
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
结果每次进行更新或查询时候就会抛出异常
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 42102, SQLState: 42S02
最终的异常显示为表不存在:
org.h2.jdbc.JdbcSQLException: Table "USER" not found; SQL statement:
实体如下:
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column
private String username;
通过spi-sqlexceptionhelper-table-club-not-found的问题得到了解决。
只需要将spring.jpa.hibernate.ddl-auto
设置为update
,对应的yaml配置如下:
spring:
jpa:
hibernate:
ddl-auto: update