Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to validate a newly established connection

"Failed to validate a newly established connection" error occurs.

I googled and read every question related to this error. But did not able to find solution.

I'm using spring-boot-starter-data-jpa.

It works without any errors with Postgresql. But I want to use embedded database!!!

application.properties:

#We don't need JMX here - disabling it allows for faster startup
spring.jmx.enabled=false
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop

spring.datasource.driver-class-name=org.hsqldb.jdbcDriver
spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
spring.datasource.url=jdbc:hsqldb:file:${user.home}/db/data;user=sa;password=123;
spring.datasource.username=sa
spring.datasource.password=123

Header of MainApplication class:

@ComponentScan(value = {"db", "app", "ui"})
@EnableJpaRepositories(basePackages = "db")
@EntityScan(basePackages = "db")
@EnableTransactionManagement
@SpringBootApplication

This error thrown only when I use embedded databases (at least Derby, HSQLDB) and not always. Sometimes it starts normally, finds and saves entities without errors, but sometimes occurs after waiting some period or immediately after successful transaction.

How can I solve this problem?

like image 716
SparX Avatar asked Oct 13 '15 10:10

SparX


2 Answers

Your validation query is the problem. While SELECT 1 without FROM works in Postgres, it is not valid in hsqldb.

See this answer for suggested validation queries for different databases

like image 58
jny Avatar answered Sep 22 '22 00:09

jny


Try it without the validation query. If the HSQLDB driver is JDBC4 compliant it should use and work with the Connection.isValid(int timeout) method.

like image 29
Robert Niestroj Avatar answered Sep 25 '22 00:09

Robert Niestroj