Warm tip: This article is reproduced from stackoverflow.com, please click
hibernate java jpa spring spring-boot

H2 Database created with spring-boot-starter-data-jpa but not with spring-boot-starter-data-jdbc

发布于 2020-04-20 11:16:12

I am new in Spring. I am trying to work with H2 Database and JDBC (not JPA/Hibernate).

So with Spring Initializr, when i add theses dependencies :

  • spring-boot-starter-web
  • spring-boot-starter-data-jpa
  • h2

and putting this property to true : spring.h2.console.enabled=true

The database mem:testdb is created and i can connect to it at : localhost:8080/h2-console

But when i change the jpa dependency to :

  • spring-boot-starter-data-jdbc

The database is not created and I have this error message :

Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149 (Help)

So I would like to know why it doesn't work with JDBC, and if you know a solution to make it work.

I found two articles on the web, and it seems they can have the database created with JDBC :

UPDATE :

I tried to do the same thing at home in my personal computer and it works...

I don't know why it doesn't work in job computer although it works with JPA.

In the logs, it is missing these lines :

com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...

com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.

o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:testdb'

UPDATE2 :

I found the solution :

As I said, I am using Spring Initializr to bootstrap the project. In the job pc, I was not able to use the last version of Spring boot (2.2.4), so i choosed 2.1.12

Version Spring Boot

With this version, it works with JPA but not with JDBC...

Questioner
gstra
Viewed
1.7k
gstra 2020-02-06 17:17

I found the solution :

As I said, I am using Spring Initializr to bootstrap the project. In the job pc, I was not able to use the last version of Spring boot (2.2.4), so i choosed 2.1.12

Version Spring Boot

With this version, it works with JPA but not with JDBC...