简体   繁体   English

使用 Grails 3 进行 Hibernate 5 搜索

[英]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.我正在使用 Grails 3.1.4,我想使用 Hibernate-Search 对我的实体进行全文搜索。

In my build.gradle I have included Hibernate 5 and Hibernate Search在我的 build.gradle 中,我包含了 Hibernate 5 和 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:如果我将@Indexed添加到我的域类之一, @Indexed出现以下错误:

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?有没有办法让 Hibernate Search 与 Grails 域类一起工作?

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.巧合的是,我目前正在移植旧的 Grails 2 Hibernate Search 插件以与 Grails 3.1.x 和 Hibernate 5 兼容。一旦我创建它,原作者就会合并我的 PR。 I just finished the development if you want to give it a try:如果您想尝试一下,我刚刚完成了开发:

https://github.com/lgrignon/grails-hibernate-search-plugin 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. PR 已合并,我刚刚在 bintray 上发布,这是用于插件分发的新 Grails 3 平台。 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" }要尝试针对 Grails 3.1.x / GORM 5 的新版 Grails Hibernate Search 2.0:添加以下存储库maven { url "http://idcapture.bintray.com/plugins" }

And add the following to your dependencies compile("org.grails.plugins:hibernate-search:2.0")并将以下内容添加到您的依赖项compile("org.grails.plugins:hibernate-search:2.0")

it should work :)它应该工作:)

Hope it helps!希望能帮助到你!

The Grails 3.1.4 already includes GORM 5 Suite , means that the following lines in your ' build.gradle ' file are probably redundant: Grails 3.1.4 已经包含GORM 5 Suite ,这意味着您的“ build.gradle ”文件中的以下几行可能是多余的:

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 .据我所知,通过使用Grails Hibernate search Plugin ,hibernate 搜索应该可以很好地与 Grails 配合使用。

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).但是,如果您已经在使用 Grails 3.1.4,那么最简单的方法可能是使用GORM 套件(Grails 对象关系映射)。 The GORM enables simple access to the database, remains your code clear and more readable. GORM 支持对数据库的简单访问,使您的代码保持清晰且更具可读性。

如果您使用的是“org.hibernate:hibernate-core:5.0.9.Final”,那么您需要获取 Hibernate Search 的兼容版本:“org.hibernate:hibernate-search-orm:5.5.4.Final”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM