0

我在 Websphere Application Server 6.1 中使用 Hibernate 3。我正在使用 JNDI 连接到我的数据源。我在管理控制台中检查了连接,连接成功。但是当我在服务器中部署我的项目并使用 JNDI 连接到数据源时,我收到以下错误消息。

Caused by: java.lang.NullPointerException
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:159)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)

它显示原因:null。

我使用 Oracle 10g 数据库。

我在日志中看到了更多异常。这与这个问题有关吗?

00000027 RegisteredRes E   WTRN0078E: An attempt by the transaction manager to call start on a transactional resource has resulted in an error. The error code was XAER_RMERR. The exception stack trace follows: oracle.jdbc.xa.OracleXAException
    at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1157)
    at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:295)
    at com.ibm.ws.rsadapter.spi.WSRdbXaResourceImpl.start(WSRdbXaResourceImpl.java:1324)
    at com.ibm.ejs.j2c.XATransactionWrapper.start(XATransactionWrapper.java:1467)
    at com.ibm.ws.Transaction.JTA.JTAResourceBase.start(JTAResourceBase.java:141)
    at com.ibm.ws.Transaction.JTA.RegisteredResources.startRes(RegisteredResources.java:1103)
    at com.ibm.ws.Transaction.JTA.RegisteredResources.enlistResource(RegisteredResources.java:525)
    at com.ibm.ws.Transaction.JTA.TransactionImpl.enlistResource(TransactionImpl.java:3219)
    at com.ibm.ws.Transaction.JTA.TranManagerSet.enlist(TranManagerSet.java:396)
    at com.ibm.ejs.j2c.XATransactionWrapper.enlist(XATransactionWrapper.java:693)
    at com.ibm.ejs.j2c.ConnectionManager.lazyEnlist(ConnectionManager.java:1723)
    at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.lazyEnlist(WSRdbManagedConnectionImpl.java:2109)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.beginTransactionIfNecessary(WSJdbcConnection.java:600)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.getMetaData(WSJdbcConnection.java:1533)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:116)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)

另一个例外是

    00000027 XATransaction E   J2CA0030E: Method enlist caught javax.transaction.SystemException: XAResource start association error:XAER_RMERR
    at com.ibm.ws.Transaction.JTA.RegisteredResources.startRes(RegisteredResources.java:1154)
    at com.ibm.ws.Transaction.JTA.RegisteredResources.enlistResource(RegisteredResources.java:525)
    at com.ibm.ws.Transaction.JTA.TransactionImpl.enlistResource(TransactionImpl.java:3219)
    at com.ibm.ws.Transaction.JTA.TranManagerSet.enlist(TranManagerSet.java:396)
    at com.ibm.ejs.j2c.XATransactionWrapper.enlist(XATransactionWrapper.java:693)
    at com.ibm.ejs.j2c.ConnectionManager.lazyEnlist(ConnectionManager.java:1723)
    at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.lazyEnlist(WSRdbManagedConnectionImpl.java:2109)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.beginTransactionIfNecessary(WSJdbcConnection.java:600)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.getMetaData(WSJdbcConnection.java:1533)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:116)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
Caused by: oracle.jdbc.xa.OracleXAException
    at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1157)
    at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:295)
    at com.ibm.ws.rsadapter.spi.WSRdbXaResourceImpl.start(WSRdbXaResourceImpl.java:1324)
    at com.ibm.ejs.j2c.XATransactionWrapper.start(XATransactionWrapper.java:1467)
    at com.ibm.ws.Transaction.JTA.JTAResourceBase.start(JTAResourceBase.java:141)
    at com.ibm.ws.Transaction.JTA.RegisteredResources.startRes(RegisteredResources.java:1103)
while trying to enlist resources from datasource jdbc/OracleData with the Transaction Manager for the current transaction, and threw a ResourceException.

下面是我的休眠配置文件:

<hibernate-configuration>
    <session-factory>
        <property name="dialect">
            org.hibernate.dialect.Oracle10gDialect
        </property>
        <property name="hibernate.transaction.factory_class">
            org.hibernate.transaction.JTATransactionFactory
        </property>
        <property name="hibernate.transaction.manager_lookup_class">
            xxx.xxx.xxx.WebSphereExtendedJTATransactionLookup
        </property>
        <property name="jta.UserTransaction">
            java:comp/UserTransaction
        </property>
    </session-factory>
</hibernate-configuration>

这里WebSphereExtendedJTATransactionLookup实现了 org.hibernate.transaction.TransactionManagerLookup

这就是我创建会话的方式

final Configuration configuration = new AnnotationConfiguration();
configuration.setProperty("hibernate.connection.datasource", dataSource);
configuration.setProperty(org.hibernate.cfg.Environment.SHOW_SQL, System.getProperty(SHOW_SQL,"false"));
configuration.configure();
return configuration.buildSessionFactory();
4

1 回答 1

0

不幸的是,如果不查看您的配置文件,我不能说太多,但我会试一试。此错误似乎是您的 App 和 JNDI 池之间的连接配置有问题。

  • 确保您的部署描述符(web.xml)包含 JNDI 连接的配置,例如:
    
        <resource-ref>
            <description>Your New DataSource</description>
            <res-ref-name>jdbc/mysqlblogpostdataref</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
        </resource-ref>
    
  • 并在您的 hibernate.cfg(假设您没有使用 Spring)上查找配置问题,这里还有另一个例子:


<property name="current_session_context_class">thread</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/mysqlblogpostdataref</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
此外,请确保验证您 context.xml 文件中的配置,如此处引用的配置休眠以通过 JNDI 数据源连接到数据库

其他示例的来源:http: //jefferyhaynes.net/2009/11/29/websphere-hibernate-datasource-configuration-for-mysql/

编辑 根据您的更新,我能够进行一些研究,看看我发现了什么:

(来自:IBM

错误是事务管理器无法将事务转换为 XA 事务。具体来说,Oracle 返回了一个错误 XAER_RMERR,错误代码号 65535。ORA-65535 不是一个有效的错误代码,XAER_RMERR 本质上意味着 XA 出了问题。这表明您的 Oracle 数据库未配置为支持 XA 事务。因此,当 WebSphere Application Server 事务管理器指示 Oracle 事务管理器参与此 XA 事务时,Oracle 无法遵守并抛出此异常。

另外,请确保查看您的 context.xml 和 web.xml 文件,在使用 WS 时,我曾经忘记配置它们。

于 2013-06-05T14:39:01.140 回答