2

我正在使用 Grails 3.1.4,我想使用 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"

如果我添加@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)

有没有办法让 Hibernate Search 与 Grails 域类一起工作?

4

3 回答 3

1

巧合的是,我目前正在移植旧的 Grails 2 Hibernate Search 插件以兼容 Grails 3.1.x 和 Hibernate 5。原作者将在我创建 PR 后立即合并。如果您想尝试一下,我刚刚完成了开发:

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

编辑

PR 合并了,我刚刚发布在 bintray 上,这是新的 Grails 3 插件分发平台。要试用 Grails 3.1.x / GORM 5 的新版本 Grails Hibernate Search 2.0:添加以下存储库 maven { url "http://idcapture.bintray.com/plugins" }

并将以下内容添加到您的依赖项中 compile("org.grails.plugins:hibernate-search:2.0")

它应该工作:)

希望能帮助到你!

于 2016-10-04T16:40:40.503 回答
0

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

于 2016-10-05T09:54:48.530 回答
0

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"

据我所知,通过使用Grails Hibernate search Plugin ,休眠搜索应该可以很好地与 Grails 配合使用。

但是,如果您已经在使用 Grails 3.1.4,那么最简单的方法可能是使用GORM 套件(Grails Object-Relational Mapping)。GORM 支持对数据库的简单访问,使您的代码保持清晰且更具可读性。

于 2016-10-03T04:40:49.533 回答