【发布时间】:2021-12-01 10:42:02
【问题描述】:
我的 Spring boot JPA 实体定义为:
@Entity
@Immutable
@Table(name = "CAR", schema="MYSCHEMA") //DB2 requires schema so this works on DB2 but not on H2
//@Table(name = "CAR") // this works on H2 but not on DB2 as it requires schema
public class CarEntity implements Serializable {
...
上述方法在 DB2 中可以正常工作,但在 H2 中却不行。
在 application.properties 中,我有以下设置:
spring.datasource.url=jdbc:h2:mem:MYDB"
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.validationQuery=SELECT 1
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
当我执行 maven>Install 时,出现错误: org.hibernate.tool.schema.spi.CommandAcceptanceException:执行 DDL 时出错“ 创建表 MYSCHEMA.CAR (... ...
原因:org.h2.jdbc.JdbcSQLSyntaxErrorException:找不到架构“MYSCHEMA”; SQL 语句: 公共类 CarEntity 实现可序列化 { ...
我希望在 H2 上创建模式,因为我在 @Table 注释中提供了它,但这并没有发生。我错过了什么?
【问题讨论】:
标签: spring-boot hibernate spring-data-jpa h2 database-schema