"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?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With