使用Hibernate的Weblogic获取javax.persistence.PersistenceException:org.hibernate.exception.GenericJDBCException:无法打开连接

时间:2015-04-22 14:36:11

标签: oracle hibernate jpa weblogic jta

我从JBoss迁移到Weblogic 12C,所有项目都在JBoss上运行良好,但是当尝试迁移到Weblogic时我有这个错误。 所以有些背景:

我的数据库: Oracle XE 应用程序服务器: WebLogic 12C

在启动脚本 startWebLogic.cmd 上我添加了:

set PRE_CLASSPATH=%MW_HOME%\oracle_common\modules\javax.persistence_2.1.jar;%MW_HOME%\wlserver\modules\com.oracle.weblogic.jpa21support_1.0.0.0_2-1.jar

在服务中的Weblogic控制台上 - >数据源我创建了一个数据源

名称: OracleDS

JNDI名称: u_interface

网址: jdbc:oracle:thin:@localhost:1521:xe

驱动程序类: oracle.jdbc.xa.client.OracleXADataSource

我可以在JNDI名称上看到u_interface在那里。

我能够在Weblogic上测试与数据库的连接。

现在我的申请:

的pom.xml

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.6.0.Final</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version>
    <type>jar</type>
    <scope>provided</scope>
</dependency>

的persistence.xml

<persistence-unit
name="OracleDS"
transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>u_interface</jta-data-source>
    <properties>
        <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
            <!--  property name="hibernate.hbm2ddl.auto" value="validate"/-->
            <!--property name="hibernate.show_sql" value="true" /-->
            <property name="hibernate.default_batch_fetch_size" value="8"/>
            <property name="hibernate.max_fetch_depth" value="3"/>
    </properties>

我有实体经理的EJB:

    @Stateful(mappedName="/ModuleDao")
  public class ModuleDao implements ModuleDaoRemote {

     @PersistenceContext(unitName = "OracleDS", type = PersistenceContextType.TRANSACTION)
     private EntityManager em;

您可以在堆栈跟踪中看到的方法getModuleByName。

@SuppressWarnings("unchecked")
    public Module getModuleByName(String name) {
        List<Module> local = null;
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery<Module> cq = cb.createQuery(Module.class);
        Root<Module> root = cq.from(Module.class);

        Predicate cond1 = cb.equal(root.get(Module_.name), name);
        cq.where(cb.and(cond1));

        Query query = getEntityManager().createQuery(cq);
        local = query.getResultList();
        if(local != null && !local.isEmpty()) {
            return local.get(0);        
        } else {
            return null;
        }
    }

我收到错误

local = query.getResultList();

界面:

@Remote
public interface ModuleDaoRemote

所以在另一个类中,我成功地注入了EJB,但是当我调用方法时

  

getModuleByName(“Some string”)

我收到错误:

Apr 22, 2015 3:58:57 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: null
<22-Apr-2015 15:58:57 o'clock CEST> <Warning> <org.hibernate.engine.jdbc.spi.SqlExceptionHelper> <BEA-000000> <SQL Error: 0, SQLState: null>
Apr 22, 2015 3:58:57 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: java.lang.NullPointerException
<22-Apr-2015 15:58:57 o'clock CEST> <Error> <org.hibernate.engine.jdbc.spi.SqlExceptionHelper> <BEA-000000> <java.lang.NullPointerException>
Apr 22, 2015 3:58:57 PM org.hibernate.engine.internal.StatisticalLoggingSessionEventListener end
INFO: Session Metrics {
    81423 nanoseconds spent acquiring 1 JDBC connections;
    0 nanoseconds spent releasing 0 JDBC connections;
    7839815 nanoseconds spent preparing 1 JDBC statements;
    0 nanoseconds spent executing 0 JDBC statements;
    0 nanoseconds spent executing 0 JDBC batches;
    0 nanoseconds spent performing 0 L2C puts;
    0 nanoseconds spent performing 0 L2C hits;
    0 nanoseconds spent performing 0 L2C misses;
    0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
    7610 nanoseconds spent executing 1 partial-flushes (flushing a total of 0 entities and 0 collections)
}
Apr 22, 2015 3:58:57 PM com.sun.xml.ws.server.sei.TieHandler createResponse
SEVERE: EJB Exception: ; nested exception is:
        javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
javax.ejb.EJBException: EJB Exception: ; nested exception is:
        javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
        at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.unwrapRemoteException(RemoteBusinessIntfProxy.java:117)
        at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:97)
        at com.sun.proxy.$Proxy191.getModuleByName(Unknown Source)
        at com.example.ejb.module.Maestro.getModuleByName(Maestro.java:81)
        at com.example.webservice.ModuleLauncher.launch(ModuleLauncher.java:52)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at weblogic.wsee.jaxws.WLSInstanceResolver$WLSInvoker.invoke(WLSInstanceResolver.java:117)
        at weblogic.wsee.jaxws.WLSInstanceResolver$WLSInvoker.invoke(WLSInstanceResolver.java:91)
        at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:149)
        at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:88)
        at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
        at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
        at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
        at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
        at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:419)
        at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:868)
        at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:422)
        at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:169)
        at weblogic.wsee.jaxws.WLSServletAdapter.handle(WLSServletAdapter.java:199)
        at weblogic.wsee.jaxws.HttpServletAdapter$AuthorizedInvoke.run(HttpServletAdapter.java:640)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
        at weblogic.wsee.util.ServerSecurityHelper.authenticatedInvoke(ServerSecurityHelper.java:108)
        at weblogic.wsee.jaxws.HttpServletAdapter$3.run(HttpServletAdapter.java:284)
        at weblogic.wsee.jaxws.HttpServletAdapter.post(HttpServletAdapter.java:293)
        at weblogic.wsee.jaxws.JAXWSServlet.doRequest(JAXWSServlet.java:128)
        at weblogic.servlet.http.AbstractAsyncServlet.service(AbstractAsyncServlet.java:99)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
        at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:243)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3432)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
        at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
        at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)
        at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)
        at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
        at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)
        at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
        at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458)
        at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:67)
        at com.example.ejb.dao.ModuleDao.getModuleByName(ModuleDao.java:77)
        at com.example.ejb.dao.ModuleDao_b09ccg_ModuleDaoRemoteImpl.__WL_invoke(Unknown Source)
        at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:34)
        at com.example.ejb.dao.ModuleDao_b09ccg_ModuleDaoRemoteImpl.getModuleByName(Unknown Source)
        at com.example.ejb.dao.ModuleDao_b09ccg_ModuleDaoRemoteImpl_CBV.getModuleByName(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:84)
        ... 46 more
Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
        at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:235)
        at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:171)
        at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:63)
        at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:162)
        at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186)
        at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:160)
        at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1885)
        at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1862)
        at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839)
        at org.hibernate.loader.Loader.doQuery(Loader.java:910)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
        at org.hibernate.loader.Loader.doList(Loader.java:2554)
        at org.hibernate.loader.Loader.doList(Loader.java:2540)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
        at org.hibernate.loader.Loader.list(Loader.java:2365)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497)
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
        at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
        at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)
        at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
        at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
        at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449)
        ... 57 more
Caused by: java.sql.SQLException: java.lang.NullPointerException
        at weblogic.jdbc.common.internal.JDBCUtil.wrapAndThrowResourceException(JDBCUtil.java:278)
        at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:416)
        at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:393)
        at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139)
        at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380)
        at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:228)
        ... 78 more
Caused by: java.lang.NullPointerException
        at weblogic.security.SimpleCallbackHandler.<init>(SimpleCallbackHandler.java:38)
        at weblogic.jdbc.common.internal.RmiDataSource.getSubject(RmiDataSource.java:466)
        at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:407)
        ... 82 more

<22-Apr-2015 15:58:57 o'clock CEST> <Error> <com.sun.xml.ws.server.sei.TieHandler> <BEA-000000> <EJB Exception: ; nested exception is:
        javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
javax.ejb.EJBException: EJB Exception: ; nested exception is:
        javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
        at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.unwrapRemoteException(RemoteBusinessIntfProxy.java:117)
        at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:97)
        at com.sun.proxy.$Proxy191.getModuleByName(Unknown Source)
        at com.example.ejb.module.Maestro.getModuleByName(Maestro.java:81)
        at com.example.webservice.ModuleLauncher.launch(ModuleLauncher.java:52)
        Truncated. see log file for complete stacktrace
Caused By: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
        at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458)
        at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:67)
        at com.example.ejb.dao.ModuleDao.getModuleByName(ModuleDao.java:77)
        Truncated. see log file for complete stacktrace
Caused By: org.hibernate.exception.GenericJDBCException: Could not open connection
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
        at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:235)
        at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:171)
        Truncated. see log file for complete stacktrace
Caused By: java.sql.SQLException: java.lang.NullPointerException
        at weblogic.jdbc.common.internal.JDBCUtil.wrapAndThrowResourceException(JDBCUtil.java:278)
        at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:416)
        at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:393)
        at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139)
        at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.NullPointerException
        at weblogic.security.SimpleCallbackHandler.<init>(SimpleCallbackHandler.java:38)
        at weblogic.jdbc.common.internal.RmiDataSource.getSubject(RmiDataSource.java:466)
        at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:407)
        at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:393)
        at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139)
        Truncated. see log file for complete stacktrace

需要一些帮助! 请随时询问更多信息。

3 个答案:

答案 0 :(得分:0)

我曾经在WebLogic上工作,现在没有任何东西要测试,但看起来JPA jta-data-source名称似乎不完整,不需要是java: // u_interface?

答案 1 :(得分:0)

所以,现在它的工作。

由于Weblogic是封闭源代码,并且NPE在应用程序服务器代码上,我试图更改Hibernate版本,我想在Weblogic 12C和Hibernate最新版本(4.3.9)之间存在一些冲突,因为使用Hibernate 4.1 .1现在正在运作。

感谢您的帮助。

答案 2 :(得分:0)

我不确定我的解决方案的公平性,但对weblogic有很多经验。

您正在使用hibernate-entitymanager 3.6,它提供了jpa 2.0。尝试将hibernate-entitymanager升级到最新版本或将项目降级到jpa 2.0

就我个人而言,weblogic痛苦地适用于内部jar修改。如果您受限于应用程序服务器选择降级到jpa2.0将是最好的解决方案。