我需要将一个使用hibernate的项目从Jboss迁移到weblogic。目前我正在使用此配置:
持久性.xml
<persistence-unit name="pagosHibernate" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>...</class>
<properties>
<property name="hibernate.ejb.cfgfile" value="META-INF/hibernate.cfg.xml"/>
</properties>
</persistence-unit>
hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="connection.datasource">MyDS</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
</session-factory>
</hibernate-configuration>
代码是:
EntityManager em = this.factory.createEntityManager();
EntityTransaction entityTransaction = em.getTransaction();
entityTransaction.begin();
...
em.persist(device);
entityTransaction.commit();
但我得到:
java.sql.SQLException: Cannot call commit when using distributed transactions
谢谢
最佳答案
Hibernate 配置中使用的数据源“MyDS”看起来像 XA 数据源。 在您的情况下,应使用非 XA 数据源。在Weblogic中配置DataSource时,您必须选择合适的瘦驱动程序。希望这会有所帮助。
关于java - Weblogic 和 hibernate 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33965529/