Failed to validate a newly established connection

匿名 (未验证) 提交于 2019-12-03 00:46:02

问题:

"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?

回答1:

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



回答2:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!