我正在使用数据源连接到 Oracle 数据库并插入数据。下面是我的休眠配置条目:
<hibernate-configuration>
<session-factory>
<property name="connection.datasource">jdbc/LOCAL_ORACLE</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
</session-factory>
</hibernate-configuration>
下面是保存数据的代码片段。
final Configuration cfg = new Configuration().addResource("SampleTable.hbm.xml").configure();
final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
sessionFactory = cfg.buildSessionFactory(serviceRegistry);
session = sessionFactory.openSession();
txn = session.beginTransaction();
session.save(cs90spTransDetails);
txn.commit();
我面临的问题是当txn.commit()被称为休眠时抛出以下错误:
[4/24/12 19:25:13:675 IST] 0000001a SystemErr R Caused by: org.hibernate.TransactionException: unable to commit against JDBC connection
[4/24/12 19:25:13:675 IST] 0000001a SystemErr R at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doCommit(JdbcTransaction.java:116)
[4/24/12 19:25:13:675 IST] 0000001a SystemErr R at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:178)
[4/24/12 19:25:13:675 IST] 0000001a SystemErr R ... 13 more
[4/24/12 19:25:13:675 IST] 0000001a SystemErr R Caused by: java.sql.SQLException: DSRA9350E: Operation Connection.commit is not allowed during a global transaction.
[4/24/12 19:25:13:675 IST] 0000001a SystemErr R at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.commit(WSJdbcConnection.java:1064)
[4/24/12 19:25:13:675 IST] 0000001a SystemErr R at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doCommit(JdbcTransaction.java:112)
注意:如果我使用hibernate.connection.driver_class 和 hibernate.connection.url连接到数据库,上面的代码可以正常工作。数据毫无问题地存储在数据库中。
我确定我做错了什么,我无法弄清楚。有人可以告诉我我错过了什么。
谢谢你。杰伊·钱德兰。