面临错误 TranManagerSet 与 Websphere 8.5 上的 TransactionManager 不兼容。创建 Hibernate 搜索索引

Facing error TranManagerSet incompatible with TransactionManager On Websphere 8.5. Creating Hibernate Search Index

我正在尝试使用 Hibernate Search、Lucene 和 persistence.xml 文件在 Elastic 服务器上执行初始索引。当我 运行 Websphere 上的索引创建过程时,服务器引发以下异常,整个过程在 TOMCAT & TC 服务器上运行良好。这也只有在 hibernate.cfg.xml 的帮助下才能实现。我们在项目中也有 hibernate.cfg.xml 文件。

我还提出了一个较早的问题,当时这不适用于 hibernate.cfg.xml 并且抛出错误。这是较早的线程,后来让我介绍了 persistence.xml 路径。 link 是 .

首先是异常,执行以下代码行后:

   fullTextEntityManager.createIndexer().startAndWait();

异常:

00000177 SystemOut     O [org.hibernate.search.exception.impl.LogErrorHandler](ERROR): HSEARCH000058: 
HSEARCH000116: Unexpected error during MassIndexer operation
org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException: Could not obtain WebSphere TransactionManager
    at org.hibernate.engine.transaction.jta.platform.internal.WebSphereJtaPlatform.locateTransactionManager(WebSphereJtaPlatform.java:66)
    at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.retrieveTransactionManager(AbstractJtaPlatform.java:87)
    at org.hibernate.search.batchindexing.impl.BatchTransactionalContext.lookupTransactionManager(BatchTransactionalContext.java:54)
    at org.hibernate.search.batchindexing.impl.BatchTransactionalContext.<init>(BatchTransactionalContext.java:43)
    at org.hibernate.search.batchindexing.impl.BatchIndexingWorkspace.runWithErrorHandler(BatchIndexingWorkspace.java:120)
    at org.hibernate.search.batchindexing.impl.ErrorHandledRunnable.run(ErrorHandledRunnable.java:33)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:522)
    at java.util.concurrent.FutureTask.run(FutureTask.java:277)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.lang.Thread.run(Thread.java:785)
Caused by: java.lang.ClassCastException: com.ibm.ws.tx.jta.TranManagerSet incompatible with javax.transaction.TransactionManager
    at org.hibernate.engine.transaction.jta.platform.internal.WebSphereJtaPlatform.locateTransactionManager(WebSphereJtaPlatform.java:63)
    ... 10 more

配置和代码详情如下:

Java 使用代码:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPAManager");
EntityManager em = emf.createEntityManager();
String message = "";
EntityTransaction tx = em.getTransaction();
             tx.begin();

             ProgressMonitor progressMonitor = new ProgressMonitor();
             FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
             fullTextEntityManager.createIndexer().startAndWait();

             tx.commit();

Persistence.xml

  <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
                 version="2.0">
       <persistence-unit name="JPAManager" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
     <jta-data-source>jdbc/[youtDataSourceName]</jta-data-source>
<properties>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />

<property name="hibernate.search.default.indexmanager" value="elasticsearch"></property>
        <property name="hibernate.search.default.elasticsearch.host" value="http://ip:9400"></property>
        <property name="hibernate.search.default.elasticsearch.required_index_status" value="yellow"></property>
         <property name="hibernate.search.default.indexwriter.infostream" value="true"></property>

        </properties>
    </persistence-unit>
    </persistence>

与 Hibernate Search、Elastic Search 和我们目前拥有的其他依赖项相关的 Jar 文件:

发现问题出在我在 WAS 服务器上的 war 文件中的以下两个 jar,并且与 websphere 的内部 jar 冲突。

删除下面两个罐子解决了它:

  1. jboss-transaction-api_1.2_spec-1.0.1.Final
  2. jta.jar

希望这对您有所帮助!