1

我正在尝试使用 Spring Data JPA、Hibernate 和 HikariCP 连接池与在 Windows 上运行的 Firebird DB 建立成功连接。我已经让所有东西都能在其他符合 JDBC 的数据库(H2、Derby、MySQL 等)上正确运行,但是当我将驱动程序 .jar 切换到 Firebird 时,我得到:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.application.Application: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
    at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
    at com.application.Application.main(Application.java:43)
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:267)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:858)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:885)
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
    ... 11 more
Caused by: org.hibernate.HibernateException: java.lang.RuntimeException: Property url does not exist on target class org.firebirdsql.ds.FBSimpleDataSource

这是我的 Spring application.properties 的摘录:

spring.jpa.properties.javax.persistence.provider=org.hibernate.jpa.HibernatePersistenceProvider

spring.jpa.properties.hibernate.hikari.dataSourceClassName=org.firebirdsql.ds.FBSimpleDataSource
spring.jpa.properties.hibernate.hikari.dataSource.url=jdbc:firebirdsql:server:/db/test123.GDB?charSet=UTF-8&amp;roleName=USER;
spring.jpa.properties.hibernate.hikari.dataSource.user=SYSDBA
spring.jpa.properties.hibernate.hikari.dataSource.password=password
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.FirebirdDialect

spring.jpa.properties.hibernate.hikari.minimumIdle=5
spring.jpa.properties.hibernate.hikari.maximumPoolSize=10
spring.jpa.properties.hibernate.hikari.idleTimeout=30000
spring.jpa.properties.hibernate.connection.handling_mode=delayed_acquisition_and_hold
spring.jpa.properties.hibernate.connection.provider_class=org.hibernate.hikaricp.internal.HikariCPConnectionProvider

我已经使用其他一些 Firebird 类进行了测试,这些类似乎为 spring.jpa.properties.hibernate.hikari.dataSourceClassName 属性实现了 javax.sql.DataSource,但都给出了无法连接异常的变体。

4

1 回答 1

0

注意:这个答案涉及 Spring Boot 中的非标准配置;正常的配置应该通过spring.datasource.*属性来完成(参见Spring Boot 文档中的使用 SQL 数据库)。

HikariCP 下的配置属性dataSource必须与目标数据源上可用的属性相匹配,并且该类org.firebirdsql.ds.FBSimpleDataSource没有属性url(如报错“Property url does not exist on target class org.firebirdsql.ds.FBSimpleDataSource”

有关可用属性的列表,请参阅org.firebirdsql.ds.FBSimpleDataSourcejavadoc。具体来说,您需要配置database和。charSetroleName

spring.jpa.properties.hibernate.hikari.dataSource.database=server:/db/test123.GDB
spring.jpa.properties.hibernate.hikari.dataSource.charSet=UTF-8
spring.jpa.properties.hibernate.hikari.dataSource.roleName=USER

连接属性必须在数据源上显式设置:您不能在属性中提供这些属性database(本质上是没有jdbc:firebirdsql:前缀和属性的 JDBC URL)。

我创建了改进票JDBC-521以添加一个url(或可能jdbcUrl)在未来版本中接受完整 JDBC URL 的属性。


有兴趣的可以看后续讨论HikariCP Connection Pool won't connect to Firebird DataSource

于 2018-02-21T17:42:35.980 回答