尝试构建索引时出现 Hibernate Search 异常
Hibernate Search exception while trying to build indexes
我正在尝试为休眠 OGM mongo 数据库应用程序添加休眠搜索支持。当我尝试使用 fullTextEntityManager.createIndexer(Post.class)
.startAndWait();
行重建索引时,我经常遇到以下异常。
HSEARCH000058: HSEARCH000116: Unexpected error during MassIndexer operation
java.lang.NoSuchMethodError: org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.getIdPropertyName()Ljava/lang/String;
at org.hibernate.ogm.massindex.impl.TupleIndexer.idInString(TupleIndexer.java:128) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.ogm.massindex.impl.TupleIndexer.createAddLuceneWork(TupleIndexer.java:119) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.ogm.massindex.impl.TupleIndexer.index(TupleIndexer.java:109) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.ogm.massindex.impl.TupleIndexer.index(TupleIndexer.java:89) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.ogm.massindex.impl.TupleIndexer.runInNewTransaction(TupleIndexer.java:216) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.ogm.massindex.impl.TupleIndexer.run(TupleIndexer.java:189) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.ogm.massindex.impl.OptionallyWrapInJTATransaction.consume(OptionallyWrapInJTATransaction.java:104) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.ogm.datastore.mongodb.MongoDBDialect.forEachTuple(MongoDBDialect.java:762) ~[hibernate-ogm-mongodb-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.ogm.dialect.impl.ForwardingGridDialect.forEachTuple(ForwardingGridDialect.java:168) [hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.ogm.massindex.impl.BatchIndexingWorkspace.run(BatchIndexingWorkspace.java:77) [hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_60]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
我的配置如下。
ORM层的POM文件:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-mongodb</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossts</groupId>
<artifactId>jbossjta</artifactId>
<version>4.16.4.Final</version>
</dependency>
<!--Hibernate search-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
<version>5.5.3.Final</version>
</dependency>
<!-- Infinispan integration -->
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-directory-provider</artifactId>
<version>8.2.4.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
(我不得不从 hibernate-search 依赖项中排除 hibernate-core 以摆脱 Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'searchIndexBuilder': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/tool/schema/spi/DelayedDropRegistry
错误。我尝试了各种版本组合但没有奏效。)
Spring 配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<context:component-scan base-package="test.y"/>
<mvc:annotation-driven />
<context:property-placeholder location="classpath:system.properties" ignore-resource-not-found="true"
ignore-unresolvable="true"/>
<!--Common beans-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="ogm-jpa-tutorial" />
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<mvc:resources mapping="/css/**" location="/css"/>
<mvc:resources mapping="/js/**" location="/js"/>
<mvc:resources mapping="/fonts/**" location="/fonts"/>
<mvc:resources mapping="/images/**" location="/images"/>
<mvc:resources mapping="/uploads/**" location="/home/yasitha/Pictures/Aurudu-2017/"/>
坚持xml:
<?xml version="1.0"?>
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
版本="2.0">
<persistence-unit name="ogm-jpa-tutorial" transaction-type="RESOURCE_LOCAL">
<!-- Use Hibernate OGM provider: configuration will be transparent -->
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<class>test.y.model.Post</class>
<properties>
<property name="hibernate.ogm.datastore.provider" value="mongodb" />
<!--<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" />-->
<property name="hibernate.ogm.datastore.create_database" value="true"/>
<property name="hibernate.ogm.datastore.database" value="blog_db"/>
<property name="hibernate.search.default.directory_provider" value="filesystem"/>
<property name="hibernate.search.default.indexBase" value="/home/yasitha/lucene/indexes"/>
</properties>
</persistence-unit>
型号class:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Type(type = "objectid")
private String id;
@Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
@Column(name = "headline")
private String title;
@Column(name = "content")
private String description;
@Column(name = "imgUrl")
private String imgUrl;
已为使用休眠 OGM 插入的记录生成索引。但不能重新索引数据库中的现有记录。如果您能给我任何解决此问题的建议,我将不胜感激。 :)
您很可能使用了错误版本的 Hibernate Search。据我所知,这个版本的 OGM 应该可以与 Hibernate Search 5.6 一起使用。1.Final.
你有没有考虑过使用Hibernate OGM BOM,来避免这类问题?如果你这样做了,这个片段是你的 Hibernate OGM 及其依赖项的 POM 中唯一需要的东西:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-bom</artifactId>
<version>5.1.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-mongodb</artifactId>
</dependency>
</dependencies>
您可以找到更多信息on the official website。
我正在尝试为休眠 OGM mongo 数据库应用程序添加休眠搜索支持。当我尝试使用 fullTextEntityManager.createIndexer(Post.class)
.startAndWait();
行重建索引时,我经常遇到以下异常。
HSEARCH000058: HSEARCH000116: Unexpected error during MassIndexer operation java.lang.NoSuchMethodError: org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.getIdPropertyName()Ljava/lang/String; at org.hibernate.ogm.massindex.impl.TupleIndexer.idInString(TupleIndexer.java:128) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.ogm.massindex.impl.TupleIndexer.createAddLuceneWork(TupleIndexer.java:119) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.ogm.massindex.impl.TupleIndexer.index(TupleIndexer.java:109) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.ogm.massindex.impl.TupleIndexer.index(TupleIndexer.java:89) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.ogm.massindex.impl.TupleIndexer.runInNewTransaction(TupleIndexer.java:216) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.ogm.massindex.impl.TupleIndexer.run(TupleIndexer.java:189) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.ogm.massindex.impl.OptionallyWrapInJTATransaction.consume(OptionallyWrapInJTATransaction.java:104) ~[hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.ogm.datastore.mongodb.MongoDBDialect.forEachTuple(MongoDBDialect.java:762) ~[hibernate-ogm-mongodb-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.ogm.dialect.impl.ForwardingGridDialect.forEachTuple(ForwardingGridDialect.java:168) [hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.ogm.massindex.impl.BatchIndexingWorkspace.run(BatchIndexingWorkspace.java:77) [hibernate-ogm-core-5.1.0.Final.jar:5.1.0.Final] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_60] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_60] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
我的配置如下。 ORM层的POM文件:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-mongodb</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossts</groupId>
<artifactId>jbossjta</artifactId>
<version>4.16.4.Final</version>
</dependency>
<!--Hibernate search-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
<version>5.5.3.Final</version>
</dependency>
<!-- Infinispan integration -->
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-directory-provider</artifactId>
<version>8.2.4.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
(我不得不从 hibernate-search 依赖项中排除 hibernate-core 以摆脱 Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'searchIndexBuilder': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/tool/schema/spi/DelayedDropRegistry
错误。我尝试了各种版本组合但没有奏效。)
Spring 配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<context:component-scan base-package="test.y"/>
<mvc:annotation-driven />
<context:property-placeholder location="classpath:system.properties" ignore-resource-not-found="true"
ignore-unresolvable="true"/>
<!--Common beans-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="ogm-jpa-tutorial" />
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<mvc:resources mapping="/css/**" location="/css"/>
<mvc:resources mapping="/js/**" location="/js"/>
<mvc:resources mapping="/fonts/**" location="/fonts"/>
<mvc:resources mapping="/images/**" location="/images"/>
<mvc:resources mapping="/uploads/**" location="/home/yasitha/Pictures/Aurudu-2017/"/>
坚持xml:
<?xml version="1.0"?>
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" 版本="2.0">
<persistence-unit name="ogm-jpa-tutorial" transaction-type="RESOURCE_LOCAL">
<!-- Use Hibernate OGM provider: configuration will be transparent -->
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<class>test.y.model.Post</class>
<properties>
<property name="hibernate.ogm.datastore.provider" value="mongodb" />
<!--<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" />-->
<property name="hibernate.ogm.datastore.create_database" value="true"/>
<property name="hibernate.ogm.datastore.database" value="blog_db"/>
<property name="hibernate.search.default.directory_provider" value="filesystem"/>
<property name="hibernate.search.default.indexBase" value="/home/yasitha/lucene/indexes"/>
</properties>
</persistence-unit>
型号class:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Type(type = "objectid")
private String id;
@Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
@Column(name = "headline")
private String title;
@Column(name = "content")
private String description;
@Column(name = "imgUrl")
private String imgUrl;
已为使用休眠 OGM 插入的记录生成索引。但不能重新索引数据库中的现有记录。如果您能给我任何解决此问题的建议,我将不胜感激。 :)
您很可能使用了错误版本的 Hibernate Search。据我所知,这个版本的 OGM 应该可以与 Hibernate Search 5.6 一起使用。1.Final.
你有没有考虑过使用Hibernate OGM BOM,来避免这类问题?如果你这样做了,这个片段是你的 Hibernate OGM 及其依赖项的 POM 中唯一需要的东西:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-bom</artifactId>
<version>5.1.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-mongodb</artifactId>
</dependency>
</dependencies>
您可以找到更多信息on the official website。