0

Im trying to implement in-memory H2 DB in pring-boot app but table doesnt get populated. Im using sql file in resources to create and populate table.

.sql

CREATE TABLE WORKER(
name VARCHAR(100) NOT NULL;
role VARCHAR(100) NOT NULL;
);
INSERT INTO WORKER(name, role) VALUES('Robert', 'cleaner');
INSERT INTO WORKER(name, role) VALUES('Jane', 'manager');

.yml

spring:
  datasource:
     url: jdbc:h2:mem:mydb
     driverClassName: org.h2.Driver
     username: nm
     password: passw
 
 jpa:
   hibernate:
     ddl-auto: create-drop
   properties:
    hibernate:
       validator:
         apply_to_ddl: true
       anable_lazy_load_no_trans: true
   open-in-view: false

   database-platform: org.hibernate.dialect.H2Dialect

 h2:
  console:
    enabled: true
    path: /h2

App compiles and is running. I can access the table from H2 Console, but no data in it. I tried different configurations in yml but nothing works. Can you advice me, whether I need to have Worker entity class or some other code or initialize classes in order get table populated? Currently Im also using JPA in it. I thought that Spring boot with H2 conf should be able to create and populate table without additional classes.

mat1
  • 83
  • 10

0 Answers0