Spting Boot with Graphql Error : org.h2.jdbc.JdbcSQLSyntaxErrorException Table not found in h2 Database
Spting Boot with Graphql Error : org.h2.jdbc.JdbcSQLSyntaxErrorException Table not found in h2 Database
我使用 h2[=34 实现了 Spring Boot 和 Graphql 的例子=] 数据库.
在我 运行 程序之后,我尝试自动创建所有 表 但我在那里遇到问题。
虽然我重新定义了application.yml中的URL并为每个实体命名,但我没有解决。
这是我的 application.yml 文件,如下所示。
spring:
application:
name: springbootgraphql
datasource:
url: jdbc:h2:mem:testdb;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1
driverClassName: org.h2.Driver
username: sa
password: password
hikari:
connection-timeout: 2000
initialization-fail-timeout: 0
jpa:
database-platform: org.hibernate.dialect.H2Dialect
properties:
hibernate:
ddl-auto: update
show_sql: true
format_sql: true
enable_lazy_load_no_trans: true
generate-ddl: true
h2:
console:
enabled: true
server:
port : 8081
# http://localhost:8081/graphql
graphql:
servlet:
mapping: /graphql
这是我的错误,如下所示。
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "hospital" not found; SQL statement:
insert into hospital (id, name) values (1, 'Hospital 1') [42102-200]
这是我的 项目 link : My Project
我该如何解决?
检查这个它可能会给你解决方案
By default, data.sql scripts are now run before Hibernate is
initialized. This aligns the behavior of basic script-based
initialization with that of Flyway and Liquibase. If you want to use
data.sql to populate a schema created by Hibernate, set
spring.jpa.defer-datasource-initialization to true. While mixing
database initialization technologies is not recommended, this will
also allow you to use a schema.sql script to build upon a
Hibernate-created schema before it’s populated via data.sql.
您必须将 spring.jpa.defer-datasource-initialization
转换为 yml。
我使用 h2[=34 实现了 Spring Boot 和 Graphql 的例子=] 数据库.
在我 运行 程序之后,我尝试自动创建所有 表 但我在那里遇到问题。
虽然我重新定义了application.yml中的URL并为每个实体命名,但我没有解决。
这是我的 application.yml 文件,如下所示。
spring:
application:
name: springbootgraphql
datasource:
url: jdbc:h2:mem:testdb;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1
driverClassName: org.h2.Driver
username: sa
password: password
hikari:
connection-timeout: 2000
initialization-fail-timeout: 0
jpa:
database-platform: org.hibernate.dialect.H2Dialect
properties:
hibernate:
ddl-auto: update
show_sql: true
format_sql: true
enable_lazy_load_no_trans: true
generate-ddl: true
h2:
console:
enabled: true
server:
port : 8081
# http://localhost:8081/graphql
graphql:
servlet:
mapping: /graphql
这是我的错误,如下所示。
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "hospital" not found; SQL statement:
insert into hospital (id, name) values (1, 'Hospital 1') [42102-200]
这是我的 项目 link : My Project
我该如何解决?
检查这个
By default, data.sql scripts are now run before Hibernate is initialized. This aligns the behavior of basic script-based initialization with that of Flyway and Liquibase. If you want to use data.sql to populate a schema created by Hibernate, set spring.jpa.defer-datasource-initialization to true. While mixing database initialization technologies is not recommended, this will also allow you to use a schema.sql script to build upon a Hibernate-created schema before it’s populated via data.sql.
您必须将 spring.jpa.defer-datasource-initialization
转换为 yml。