3

我正在将我的应用程序从 MySQL 迁移到 Postgres。我的应用在 PlayFramework 上使用 Hibernate、HikariCp。在 MySQL 上一切正常。但是当我尝试切换到 Postgres 时,我得到空指针异常:-BaseHikariPool.addConnection

堆栈跟踪 :-

play.api.UnexpectedException: Unexpected exception[PersistenceException: Unable to build entity manager factory]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:166) ~[play_2.11-2.3.8.jar:2.3.8]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:130) ~[play_2.11-2.3.8.jar:2.3.8]
    at scala.Option.map(Option.scala:146) ~[scala-library-2.11.6.jar:na]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:130) ~[play_2.11-2.3.8.jar:2.3.8]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:128) ~[play_2.11-2.3.8.jar:2.3.8]
Caused by: javax.persistence.PersistenceException: Unable to build entity manager factory
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:82) ~[hibernate-entitymanager-4.3.0.CR1.jar:4.3.0.CR1]
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55) ~[hibernate-entitymanager-4.3.0.CR1.jar:4.3.0.CR1]
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) ~[hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) ~[hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]
    at play.db.jpa.JPAPlugin.onStart(JPAPlugin.java:38) ~[play-java-jpa_2.11-2.3.8.jar:2.3.8]
Caused by: org.hibernate.HibernateException: com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization
    at com.zaxxer.hikari.hibernate.HikariConnectionProvider.configure(HikariConnectionProvider.java:86) ~[HikariCP-2.3.7.jar:na]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89) ~[hibernate-core-4.3.0.CR1.jar:4.3.0.CR1]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206) ~[hibernate-core-4.3.0.CR1.jar:4.3.0.CR1]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178) ~[hibernate-core-4.3.0.CR1.jar:4.3.0.CR1]
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:265) ~[hibernate-core-4.3.0.CR1.jar:4.3.0.CR1]
Caused by: com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization
    at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:542) ~[HikariCP-2.3.7.jar:na]
    at com.zaxxer.hikari.pool.BaseHikariPool.<init>(BaseHikariPool.java:171) ~[HikariCP-2.3.7.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:60) ~[HikariCP-2.3.7.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:48) ~[HikariCP-2.3.7.jar:na]
    at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:80) ~[HikariCP-2.3.7.jar:na]
Caused by: java.lang.NullPointerException: null
    at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:446) ~[HikariCP-2.3.7.jar:na]
    at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:540) ~[HikariCP-2.3.7.jar:na]
    at com.zaxxer.hikari.pool.BaseHikariPool.<init>(BaseHikariPool.java:171) ~[HikariCP-2.3.7.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:60) ~[HikariCP-2.3.7.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:48) ~[HikariCP-2.3.7.jar:na]

持久性.xml:-

http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">

<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> 
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hibernate.use_sql_comments" value="true"/>
        <property name="hibernate.connection.provider_class" value="com.zaxxer.hikari.hibernate.HikariConnectionProvider"/>
        <property name="hibernate.hikari.dataSourceClassName" value="com.impossibl.postgres.jdbc.PGDataSource"/>
        <property name="hibernate.hikari.dataSource.host" value="jdbc:postgresql://127.0.0.1:5432"/>
        <property name="hibernate.hikari.dataSource.database" value="play"/>
        <property name="hibernate.hikari.dataSource.user" value="test"/>
        <property name="hibernate.hikari.dataSource.password" value="test_password" />
        <property name="hibernate.hikari.connectionTestQuery" value="SELECT 1" />                             
    </properties>
</persistence-unit>

Build.sbt 依赖项:-

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs,
  javaJpa,
  "org.hibernate" % "hibernate-core" % "4.3.0.CR1",
  "org.hibernate" % "hibernate-entitymanager" % "4.3.0.CR1",
  "org.hibernate.javax.persistence" % "hibernate-jpa-2.1-api" % "1.0.0.Draft-16", 
  "com.impossibl.pgjdbc-ng" % "pgjdbc-ng" % "0.5",   
  "org.scala-lang" % "scala-library" % "2.11.6",
  "com.edulify" %% "play-hikaricp" % "2.0.5"
)

有人可以在这里帮助我吗,我已经阅读了很多关于 stackoverflow 和 HikariCp github 页面的帖子,但无法确定问题。

谢谢!

4

0 回答 0