0

I implement an example of Spring Boot with Graphql by using the h2 database.

After I ran the program, I tried to create all tables automatically but I have a problem there.

I didn't solve it although I redefined the URL in application.yml and gave the name for each entity.

Here is my application.yml file which is shown below.

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

Here is my error which is shown below.

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "hospital" not found; SQL statement:
insert into hospital (id, name) values (1, 'Hospital 1') [42102-200]

Here is my project link : My Project

How can I fix it?

S.N
  • 2,157
  • 3
  • 29
  • 78

1 Answers1

3

Check this post it may give you the solution

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.

you'll have to convert spring.jpa.defer-datasource-initialization to yml tho.

ZitZit
  • 816
  • 1
  • 5
  • 10