Grails 2.4 + Hibernate 4 +可搜索插件= ClassNotFoundException:org.hibernate.impl.SessionFactoryImpl [英] Grails 2.4 + Hibernate 4 + Searchable plugin = ClassNotFoundException: org.hibernate.impl.SessionFactoryImpl

查看:136
本文介绍了Grails 2.4 + Hibernate 4 +可搜索插件= ClassNotFoundException:org.hibernate.impl.SessionFactoryImpl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我正在将一个简单的Grails应用程序与Searchable插件集成在一起。我发现的是,Searchable插件不能用于Hibernate 4库。



在这里您可以找到一个示例应用程序,其中只包含干净的Grails 2.4应用程序,仅包含Searchable插件已添加 - https://github.com/wololock/grails-searchable-example



当我运行这个应用程序时:

  runtime:hibernate4:4.3.5.5

依赖关系,它不会启动并引发异常:

  ClassNotFoundException:org.hibernate.impl.SessionFactoryImpl 

什么我发现已经是在Hibernate4 SessionFactoryImpl被移动到org.hibernate.internal包,它看起来像Compass在旧的位置寻找这个类:

  2014-10-11 19:41:58,142 [localhost-startStop-1]错误context.GrailsContextLoaderListener  - 初始化应用程序时出错:org / hibe rnate / impl / SessionFactoryImpl 
消息:org / hibernate / impl / SessionFactoryImpl
行|方法
- >> 95 | org.compass.gps.device.hibernate.lifecycle.DefaultHibernateEntityLifecycleInjector中的injectLifecycle

切换回:

  runtime:hibernate:3.6.10.17

并更改

  cache.region.factory_class ='net.sf.ehcache。 hibernate.EhCacheRegionFactory'

解决了这个问题。



我的问题是:是否有任何解决方法使用Hibernate 4中的Searchable插件,或者我们必须等待或修复Compass / Searchable源代码中的问题?你在Grails应用程序中是如何处理这个问题的? Hibrate 3.x和4.x之间有几个软件包和类名称的变化,我们将不胜感激您的提示。

,所以与Hibernate 3.x一起工作的代码在4.x中不起作用,除非极少数情况。除了名称更改之外,事情的工作方式也有很大的内部变化,因此编译的代码不一定会运行。应用程序选项#1将降级到Hibernate 3.x.配置设置包含并注释掉(BuildConfig.groovy,DataSource.groovy),所以这是一个非常快速的选择。显然,如果你依赖于4.x中添加的一个功能,这不是一个选项,这只是延迟了真正的问题,直到你必须升级Hibernate。



所有使用Hibernate 3的插件需要更新以支持Hibernate 4,或者作为替换,或者理想地支持使用一些交叉编译技巧或其他3方库。假设用户最终从3.x升级的一个插件选项是创建一个3.x分支并为Hibernate 4的插件(在主分支)启动一个新的主要版本,并进行更改以使其在4中工作。 X。使用3.x分支来支持安全更新和非常小的问题,但不要添加新功能。很多插件作者可能会采用这种方式。



在某些情况下,另一种选择最有意义 - 不要做任何事情。这适用于可搜索。可搜索的网站使用 http://www.compass-project.org/ ,该网站实际上已经死亡 - 它的最后一个版本是4年前的版本。 Shay Banon现在是 http://www.elasticsearch.org/ 的首席技术官。我相信Shay停止了Compass的工作,并开始使用Elasticsearch,因为它是不可能将Compass扩展到单个服务器之外。可以将Lucene索引存储在数据库中,但是,虽然这样可以为您提供集中的单个写入程序和一个或多个(使用db集群或类似的)集中式读取程序,但具有自定义协议的优化搜索服务器等更有意义。



还有 Solr 的共识似乎是这样的Elasticsearch是首选。 Solr Grails插件3年未更新,而且 Elasticsearch插件也变得发霉,但最近Noam Tenne接管了作为插件的领导者,并且做了很多很棒的工作,并且他在过去几个月里完成了几次发布。请注意,旧的 elasticsearch elasticsearch-gorm 插件已合并并更新,以创建新的 elasticsearch 插件。

另一种选择是使用Hibernate自己的产品 Hibernate搜索。有一个插件,但它自2012年以来没有更新过。自私这是我个人对你的偏好 - 选择这个选项,接管插件(假设肯定回复或原始作者没有回应),并将其更新为与最新的Hibernate 4.x插件兼容。这会给我们一个很好的选择Elasticsearch。



除此之外,我认为Elasticsearch是您的最佳选择。


Recently I was integrating a simple Grails application with the Searchable plugin. What I've found was that Searchable plugin does not work with Hibernate 4 library.

Here you can find a sample application that contains only clean Grails 2.4 app with only Searchable plugin added - https://github.com/wololock/grails-searchable-example

When I run this app with:

runtime ":hibernate4:4.3.5.5"

dependency, it wont start and throws an exception:

ClassNotFoundException: org.hibernate.impl.SessionFactoryImpl

What I have found already is that in the Hibernate4 SessionFactoryImpl was moved to the org.hibernate.internal package and it seems like Compass looks for this class in the old location:

2014-10-11 19:41:58,142 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: org/hibernate/impl/SessionFactoryImpl
Message: org/hibernate/impl/SessionFactoryImpl
Line | Method
->>   95 | injectLifecycle in org.compass.gps.device.hibernate.lifecycle.DefaultHibernateEntityLifecycleInjector

Switching back to the:

runtime ":hibernate:3.6.10.17"

and changing

cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'

in the DataSource.groovy resolves the problem.

My question is: is there any workaround to use Searchable plugin with Hibernate 4 or we have to wait or fix the issue in Compass/Searchable source code? How did you deal with that problem in your Grails application? I will be grateful for your tips.

解决方案

There were several package and class name changes between Hiberate 3.x and 4.x, so code that works with Hibernate 3.x won't work with 4.x except in rare cases. Beyond the name changes, there were big internal changes in how things work, so code that compiles won't necessarily run. App option #1 is to downgrade to Hibernate 3.x. The config settings for that are included and commented out (BuildConfig.groovy, DataSource.groovy), so this a very quick option. Obviously not an option if you depend on a feature added in 4.x, and this just delays the real problem until you have to upgrade Hibernate.

All plugins using Hibernate 3 need to be updated to support Hibernate 4, either as a replacement, or ideally supporting both using some cross-compile tricks or another 3rd party library. One plugin option that assumes users will eventually upgrade from 3.x is to create a 3.x branch and start a new major revision of the plugin (in the master branch) for Hibernate 4 and make the changes to get it working in 4.x. Use the 3.x branch to support security updates and very minor issues, but don't add new features. A lot of plugin authors will probably go this route.

In some cases yet another option makes the most sense - don't do anything. This applies to Searchable. Searchable uses http://www.compass-project.org/ which is effectively dead - its last release was 4 years ago. Shay Banon is now the CTO of http://www.elasticsearch.org/ I believe Shay stopped working on Compass and started Elasticsearch because it's impractical to scale Compass beyond a single server. It's possible to store the Lucene index in a database, but while that does give you a centralized single writer and one or more (with db clustering or similar) centralized reader(s), an optimized search server with custom protocols, etc. makes way more sense.

There's also Solr the consensus seems to be that Elasticsearch is preferred. The Solr Grails plugin hasn't been updated in 3 years, and the Elasticsearch plugin was getting moldy too, but recently Noam Tenne took over as the plugin lead and has done a lot of great work and he's done several releases in the last few months. Note that the old elasticsearch and elasticsearch-gorm plugins were merged and updated to create the new elasticsearch plugin.

Yet another option is to use Hibernate's own product, Hibernate Search. There's a plugin for that but it hasn't been updated since 2012. Selfishly this is my personal preference for you - choose this option, take over the plugin (assuming affirmative reply or no response from the original authors) and update it to be compatible with the latest Hibernate 4.x plugin. That would give us a good alternative to Elasticsearch.

Barring that, I think Elasticsearch is your best option.

这篇关于Grails 2.4 + Hibernate 4 +可搜索插件= ClassNotFoundException:org.hibernate.impl.SessionFactoryImpl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆