Search code examples
hibernatehibernate-searchhibernate-entitymanagerhibernate-ogm

Hibernate Search exception while trying to build indexes


I'm trying to add hibernate search support for hibernate OGM mongo DB application. I'm regularly getting following exception while I'm trying to rebuild indexes using fullTextEntityManager.createIndexer(Post.class) .startAndWait(); line.

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]

My configurations are as following. POM file in ORM layer:

    <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>

(I had to exclude hibernate-core from hibernate-search dependency to get rid of 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 error. I tried various version combinations but did not work.)

Spring config file:

<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/"/>

Persistance xml:

<?xml version="1.0"?>

http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="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>

Model 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;

Indexes has been generated for the records which were inserted with hibernate OGM. But cannot re-index existing records in the DB. I would be very thankful if you could give me any suggestion to solve this issue. :)


Solution

  • It is very likely you are using the wrong version of Hibernate Search. As far as I can see, this version of OGM should work with Hibernate Search 5.6.1.Final.

    Have you ever considered using the Hibernate OGM BOM, so as to avoid that kind of problems? If you did, this snippet is the only thing that would be required in your POM for Hibernate OGM and its dependencies:

    <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>
    

    You can find more information on the official website.