HibernatePersistence提供程序出错

时间:2014-09-03 08:40:16

标签: java spring jpa oracle11g ibm-was

我目前正在使用的应用程序使用Spring JPA,它工作正常。但是当我在Websphere应用服务器V8.5中部署它时,我在应用程序启动时会遇到异常。 使用的数据库是Oracle Oracle Database 11g Express Edition版本11.2.0.2.0。

An error occurred in the org.hibernate.ejb.HibernatePersistence persistence provider when it attempted to create the container entity manager factory for the domain persistence unit. The following error occurred: java.lang.NullPointerException
    at org.hibernate.engine.jdbc.internal.TypeInfoExtracter.extractTypeInfo(TypeInfoExtracter.java:85)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:144)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1797)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1755)
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:76)
    at com.ibm.ws.jpa.management.JPAPUnitInfo.createEMFactory(JPAPUnitInfo.java:1584)
    at com.ibm.ws.jpa.management.JPAPUnitInfo.createEntityManagerFactory(JPAPUnitInfo.java:1406)
    at com.ibm.ws.jpa.management.JPAPxmlInfo.extractPersistenceUnits(JPAPxmlInfo.java:246)
    at com.ibm.ws.jpa.management.JPAScopeInfo.processPersistenceUnit(JPAScopeInfo.java:119)
    at com.ibm.ws.jpa.management.JPAApplInfo.processModulePUs(JPAApplInfo.java:167)
    at com.ibm.ws.jpa.management.AbstractJPAComponent.startingModule(AbstractJPAComponent.java:451)
    at com.ibm.ws.jpa.management.JPAComponentImpl.startingDeployedModule(JPAComponentImpl.java:771)
    at com.ibm.ws.jpa.management.JPAComponentImpl.adjust(JPAComponentImpl.java:559)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.adjust(ApplicationMgrImpl.java:1071)
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectAdjust(DeployedApplicationImpl.java:1394)
    at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:627)
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:968)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:776)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplicationDynamically(ApplicationMgrImpl.java:1379)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2189)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:446)
    at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:389)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access$500(CompositionUnitMgrImpl.java:117)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$1.run(CompositionUnitMgrImpl.java:664)
    at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5474)
    at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5600)
    at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:678)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:622)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:1269)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:69)
    at sun.reflect.GeneratedMethodAccessor98.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:272)
    at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1152)
    at java.security.AccessController.doPrivileged(AccessController.java:298)
    at com.ibm.oti.security.CheckedAccessControlContext.securityCheck(CheckedAccessControlContext.java:30)
    at sun.misc.JavaSecurityAccessWrapper.doIntersectionPrivilege(JavaSecurityAccessWrapper.java:41)
    at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1146)
    at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:999)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:847)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:783)
    at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1335)
    at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
    at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1228)
    at com.ibm.ws.management.connector.AdminServiceDelegator.invoke(AdminServiceDelegator.java:181)
    at com.ibm.ws.management.connector.ipc.CallRouter.route(CallRouter.java:247)
    at com.ibm.ws.management.connector.ipc.IPCConnectorInboundLink.doWork(IPCConnectorInboundLink.java:360)
    at com.ibm.ws.management.connector.ipc.IPCConnectorInboundLink$IPCConnectorReadCallback.complete(IPCConnectorInboundLink.java:602)
    at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1818)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1864)

并且应用程序仍然正常,我的意思是我能够访问应用程序并使用它来执行业务逻辑。

不确定为什么每次部署应用程序时都会在SystemOut.log中记录此异常。 Persistence.xml如下所示。

<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="domain" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>java:comp/env/jdbc/MyDS</non-jta-data-source>
    <class>MyEntityClasses</class>
</persistence-unit>

有人可以告诉我为什么抛出这个例外?

这是我的Spring配置

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:jpa="http://www.springframework.org/schema/data/jpa"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/data/jpa
         http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
         http://www.springframework.org/schema/tx 
         http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
         http://www.springframework.org/schema/context 
         http://www.springframework.org/schema/context/spring-context-3.1.xsd
         http://www.springframework.org/schema/mvc
         http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
         http://www.springframework.org/schema/jee 
         http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">

<context:annotation-config/> 
<tx:annotation-driven/>
<bean id="entityManagerFactory"  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="mypersistenceunit" />
</bean>
<bean id="persistenceExceptionTranslationPostProcessor"
      class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<jpa:repositories base-package="com.domain.repository" />

1 个答案:

答案 0 :(得分:0)

Hibernate方法TypeInfo.extractTypeInfo使用jdbc DatabaseMetaData从数据库中查询数据类型。在您的情况下,您可能需要调试NullPointer。我不怀疑metaData是null,因为在Hibernate引导时调用此方法之前广泛使用它。

public static LinkedHashSet<TypeInfo> extractTypeInfo(DatabaseMetaData metaData) {
        final LinkedHashSet<TypeInfo> typeInfoSet = new LinkedHashSet<TypeInfo>();
        try {
            final ResultSet resultSet = metaData.getTypeInfo();
            try {
                while ( resultSet.next() ) {
                    typeInfoSet.add(
                            new TypeInfo(
                                    resultSet.getString( "TYPE_NAME" ),
                                    resultSet.getInt( "DATA_TYPE" ),
                                    interpretCreateParams( resultSet.getString( "CREATE_PARAMS" ) ),
                                    resultSet.getBoolean( "UNSIGNED_ATTRIBUTE" ),
                                    resultSet.getInt( "PRECISION" ),
                                    resultSet.getShort( "MINIMUM_SCALE" ),
                                    resultSet.getShort( "MAXIMUM_SCALE" ),
                                    resultSet.getBoolean( "FIXED_PREC_SCALE" ),
                                    resultSet.getString( "LITERAL_PREFIX" ),
                                    resultSet.getString( "LITERAL_SUFFIX" ),
                                    resultSet.getBoolean( "CASE_SENSITIVE" ),
                                    TypeSearchability.interpret( resultSet.getShort( "SEARCHABLE" ) ),
                                    TypeNullability.interpret( resultSet.getShort( "NULLABLE" ) )
                            )
                    );
                }
            }
            catch ( SQLException e ) {
                LOG.unableToAccessTypeInfoResultSet( e.toString() );
            }
            finally {
                try {
                    resultSet.close();
                }
                catch ( SQLException e ) {
                    LOG.unableToReleaseTypeInfoResultSet();
                }
            }
        }
        catch ( SQLException e ) {
            LOG.unableToRetrieveTypeInfoResultSet( e.toString() );
        }

        return typeInfoSet;
    }