无法验证新建立的连接 [英] Failed to validate a newly established connection

查看:77
本文介绍了无法验证新建立的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出现无法验证新建立的连接"错误.

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

我正在使用 spring-boot-starter-data-jpa.

它在使用 Postgresql 时没有任何错误.但是我想用嵌入式数据库!!!

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

MainApplication 类的标题:

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

此错误仅在我使用嵌入式数据库(至少是 Derby、HSQLDB)时抛出,并非总是如此.有时正常启动,找到并保存实体没有错误,但有时会在等待一段时间后或交易成功后立即发生.

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?

推荐答案

您的验证查询是问题所在.虽然 SELECT 1 没有 FROMPostgres 中有效,但它在 hsqldb 中无效.

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

这篇关于无法验证新建立的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆