无法启动服务jboss.persistenceunit:NullPointerException postgresql.jdbc.TypeInfoCache.getSQLType

时间:2016-03-30 08:20:28

标签: hibernate postgresql jpa jdbc jboss

我使用Liferay从Javaoss升级到WildFly 9,从Java 7升级到Java 8.我还将postgresql jdbc驱动程序更新为版本9.4-1207。

从那时起,我无法部署我的应用程序,因为它会抛出以下错误:

2016-03-30 10:02:07,404 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 201) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'TestEJBsWithArquillian.war#at.testapplication.jpa'
2016-03-30 10:02:08,544 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 201) MSC000001: Failed to start service jboss.persistenceunit."TestEJBsWithArquillian.war#at.testapplication.jpa": org.jboss.msc.service.StartException in service jboss.persistenceunit."TestEJBsWithArquillian.war#at.testapplication.jpa": java.lang.NullPointerException
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:665)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.NullPointerException
    at org.postgresql.jdbc.TypeInfoCache.getSQLType(TypeInfoCache.java:185)
    at org.postgresql.jdbc.TypeInfoCache.getSQLType(TypeInfoCache.java:180)
    at org.postgresql.jdbc.TypeInfoCache.requiresQuoting(TypeInfoCache.java:823)
    at org.postgresql.jdbc.PgDatabaseMetaData.getTypeInfo(PgDatabaseMetaData.java:2952)
    at org.hibernate.engine.jdbc.spi.TypeInfo.extractTypeInfo(TypeInfo.java:101)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:163)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
    at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)
    ... 7 more

我有以下persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="at.testapplication.jpa" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>jdbc/databasePool</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <shared-cache-mode>ALL</shared-cache-mode>
        <validation-mode>AUTO</validation-mode>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="validate"/>
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.jdbc.batch_size" value="10"/>
            <property name="hibernate.jdbc.fetch_size" value="10"/>
            <property name="hibernate.dialect" value="${testapplication.database.dialect}"/>
            <property name="hibernate.transaction.manager_lookup_class"
                      value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
            <property name="hibernate.transaction.jta.platform"
                      value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
            <property name="hibernate.search.default.directory_provider" value="filesystem"/>
            <property name="hibernate.search.default.indexBase" value="${liferay.home}/data/lucene"/>
            <property name="hibernate.cache.use_second_level_cache" value="false"/>
            <property name="hibernate.cache.use_query_cache" value="false"/>
        </properties>
    </persistence-unit>
</persistence>

这是standalone.xml(我可以从wildfly管理界面ping数据源):

<subsystem xmlns="urn:jboss:domain:datasources:3.0">
            <datasources>
                <datasource jta="true" jndi-name="java:/jdbc/databasePool" pool-name="databasePool" enabled="true" use-java-context="true" use-ccm="true">
                    <connection-url>jdbc:postgresql://localhost/db</connection-url>
                    <driver>postgresql</driver>
                    <security>
                        <user-name>admin</user-name>
                        <password>admin</password>
                    </security>
                    <validation>
                        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
                        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
                    </validation>
                </datasource>
                <drivers>
                    <driver name="postgresql" module="org.postgresql">
                        <datasource-class>org.postgresql.ds.PGConnectionPolDataSource</datasource-class>
                    </driver>
                </drivers>
            </datasources>
        </subsystem>

我可以从Wildfly管理界面ping我的databasePool。有谁知道可能导致这种情况的原因是什么?看起来JDBC驱动程序抛出了NullPointerException。我也尝试过其他版本的JDBC驱动程序,但它仍然会抛出相同的错误。

1 个答案:

答案 0 :(得分:2)

好吧,事实证明我的数据库元数据已损坏。从同事恢复数据库后,部署的应用程序就好了。