我在 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();