java - 无法验证新建立的连接

标签 java spring postgresql spring-boot spring-data-jpa

出现“无法验证新建立的连接”错误。

我用谷歌搜索并阅读了与此错误相关的每个问题。但未能找到解决方案。

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

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

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)时抛出,并非总是如此。有时启动正常,查找并保存实体没有错误,但有时等待一段时间后或交易成功后立即出现。

我该如何解决这个问题?

最佳答案

您的验证查询是问题所在。虽然没有 FROMSELECT 1Postgres 中有效,但在 hsqldb 中无效。

查看此 answer针对不同数据库的建议验证查询

关于java - 无法验证新建立的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33100423/

相关文章:

java - 创建 TomCat 6.0 Web 应用程序

java - 服务器接受套接字,但之后套接字无法接收任何内容

java - 如何在 orm.xml 中使用 SpEL?

database - Postgresql:如何应用 pg_dump --exclude-table-data 补丁?

postgresql - 在 postgresql 9.3 中是否有任何技术可以使它开始返回 1 和 0 而不是 bool 类型的 "t"和 "f"

postgresql - 由于 Postgis 问题,我的 Postgresql 数据库出现错误(找不到 $libdir/postgis-2.0?)

java - IndexOutOfBoundsException : Index: 0, 大小:0

java - KeyGenerator 特殊的 key 与特殊的种子

java - 为什么我的 Spring @Autowired 字段为空?

java - 使用 Web 服务客户端 JAXB 生成的类作为 JPA 实体