Search code examples
hibernategrailshibernate-searchgrails3

Hibernate 5 Search with Grails 3


I am using Grails 3.1.4 and I want use Hibernate-Search for full text search of my entities.

In my build.gradle I have included Hibernate 5 and Hibernate Search

compile "org.hibernate:hibernate-core:5.0.9.Final"
compile "org.hibernate:hibernate-ehcache:5.0.9.Final"
compile "org.hibernate:hibernate-search-orm"

If I add the @Indexed to one of my domain classes, I get the folling error:

ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:207)
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:687)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:523)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:55)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:365)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:354)
    at grails.boot.GrailsApp$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
    at com.myapp.Application.main(Application.groovy:8)

Is there a way to get Hibernate Search working together with Grails domain classes?


Solution

  • as a coincidence, I am currently porting the old Grails 2 Hibernate Search plugin to be compatible with Grails 3.1.x and Hibernate 5. The original author is up to merge my PR as soon as I create it. I just finished the development if you want to give it a try:

    https://github.com/lgrignon/grails-hibernate-search-plugin

    EDIT:

    The PR is merged, I just published in on bintray, which is the new Grails 3 platform for plugins distribution. To try the new version of Grails Hibernate Search 2.0 for Grails 3.1.x / GORM 5: Add the following repository maven { url "http://idcapture.bintray.com/plugins" }

    And add the following to your dependencies compile("org.grails.plugins:hibernate-search:2.0")

    it should work :)

    Hope it helps!