2

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?

Tobi
  • 2,001
  • 2
  • 27
  • 49

3 Answers3

1

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!

Louis GRIGNON
  • 699
  • 6
  • 17
0

The Grails 3.1.4 already includes GORM 5 Suite, means that the following lines in your 'build.gradle' file are probably redundant:

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

As far as I know, the hibernate search should work great with Grails, by using the Grails Hibernate search Plugin.

But, if you are already working with Grails 3.1.4, probably, the easiest way might be using the GORM suite (Grails Object-Relational Mapping). The GORM enables simple access to the database, remains your code clear and more readable.

Rotem
  • 1,381
  • 1
  • 11
  • 23
  • But I can't use the GORM suite for full text search, right? – Tobi Oct 03 '16 at 06:25
  • I think that you are right. Please look at the following link: http://omarello.com/2010/08/grails-full-text-search/ It may give you other aspect while using Grails application. – Rotem Oct 03 '16 at 07:32
  • This article references the searchable plugin which should not be used anymore: http://stackoverflow.com/a/33316237/910411 as it is based the Compass project, which is dead – Tobi Oct 03 '16 at 07:40
  • 1
    Ok in that case you may find any related functionality that already exists in The Grails 3.1.4 framework. If you are using MongoDB for example, you may find that usefull: https://spring.io/blog/2014/07/17/text-search-your-documents-with-spring-data-mongodb. Another option is using Elastic-Search. – Rotem Oct 03 '16 at 11:37
  • Yeah thx, I already decided to use ElasticSearch with the Grails ElasticSearch plugin, as it seems more powerful anyways. – Tobi Oct 03 '16 at 11:40
  • N.B. that Elasticsearch and Hibernate Search solve different aspects, they're not competing but complementary projects. Elasticsearch provides the index and query engine, Hibernate Search makes it easy to keep your ORM operations in synch with the index, and materialize Hibernate managed entities as result from your queries. For example Hibernate Search can now be used with Elasticsearch as well: http://in.relation.to/2016/09/06/ElasticsearchIntegrationBeta2/ – Sanne Oct 05 '16 at 09:56
  • @rotemy, I don't know if you saw my answer (http://stackoverflow.com/a/39857623/838712), I upgraded Grails Hibernate Search plugin so it is compatible with Grails 3 / GORM 5. If you need Hibernate Search with Grails 3, give it a try, it works for me and the question's author :) – Louis GRIGNON Oct 17 '16 at 19:25
0

If you're using "org.hibernate:hibernate-core:5.0.9.Final" then you need to get the compatible version of Hibernate Search: "org.hibernate:hibernate-search-orm:5.5.4.Final".

Sanne
  • 6,027
  • 19
  • 34