我正在使用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域类一起使用?
答案 0 :(得分: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")
它应该工作:)
希望它有所帮助!
答案 1 :(得分: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,hibernate搜索应该可以很好地与Grails一起使用。
但是,如果您已经在使用Grails 3.1.4,可能最简单的方法是使用GORM suite(Grails对象关系映射)。 GORM可以简单地访问数据库,保持代码清晰,可读性更高。
答案 2 :(得分:0)
如果您正在使用“org.hibernate:hibernate-core:5.0.9.Final”,那么您需要获得Hibernate Search的兼容版本:“org.hibernate:hibernate-search-orm:5.5.4。最后的”。