Grails 2.4 + Hibernate 4 + Search Plugin = ClassNotFoundException: org.hibernate.impl.SessionFactoryImpl

I recently integrated a simple Grails application with the Searchable plugin. I found that the Searchable plugin does not work with the Hibernate 4 library.

Here you can find an example application containing only pure Grails 2.4 applications, with an added search plugin - https://github.com/wololock/grails-searchable-example

When I launch this application using

runtime ":hibernate4:4.3.5.5" 

it does not start and throws an exception:

 ClassNotFoundException: org.hibernate.impl.SessionFactoryImpl 

I already found that in Hibernate4, SessionFactoryImpl was moved to the org.hibernate.internal package, and it seems that Compass is looking 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 

Return to the next item:

 runtime ":hibernate:3.6.10.17" 

and changes

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

in DataSource.groovy fixes the problem.

My question is: is there any workaround for using the Searchable plugin with Hibernate 4 or do we need to wait or fix the problem in the Compass / Searchable source code? How did you deal with this issue in your Grails app? I will be grateful for your advice.

+7
hibernate grails searchable
source share
2 answers

There were several changes to the package name and class between Hiberate 3.x and 4.x, so the code that works with Hibernate 3.x will not work with 4.x, except in rare cases. In addition to changing the name, there have been major internal changes in the work, so the code that compiles will not necessarily run. Variant of application No. 1 - transition to Hibernate 3.x. The configuration settings for this are included and commented out (BuildConfig.groovy, DataSource.groovy), so this is a very quick option. Obviously, this is not an option if you depend on a feature added in 4.x, and that just delays the real problem until you have to update Hibernate.

All plugins that use Hibernate 3 need to be updated to support Hibernate 4, either as a replacement, or ideally supporting both the use of cross-compilation tricks and other 3 rd party libraries. One version of the plugin, assuming that users will eventually be upgraded from 3.x, is to create a 3.x branch and start a new major revision of the plugin (in the main branch) for Hibernate 4 and make changes to make it work in 4. X . Use the 3.x branch to support security updates and very minor issues, but don't add new features. Probably many plugin authors will go this route.

In some cases, another option makes the most sense - do nothing. This refers to a search query. Searchable uses http://www.compass-project.org/ , which is virtually dead - its last release was 4 years ago. Shay Banon is now CTO at http://www.elasticsearch.org/ . I believe that Shay stopped working on Compass and started Elasticsearch because it is not practical to scale Compass outside of one server. You can save the Lucene index in the database, but while it gives you a centralized single writer and one or more (with db clustering or similar) centralized reader, an optimized search server with user protocols, etc. more sense.

There also Solr consensus seems to be preferred by Elasticsearch. The Solr Grails plugin did not update after 3 years, and the Elasticsearch plugin also became moldy, but recently Noam Tenne took on the role of the plugin and did a lot of work, and he has done several releases over the past few months. Note that the old elasticsearch and elasticsearch-gorm have been merged and updated to create a new elasticsearch plugin.

Another option is to use Hibernate's own product, Hibernate Search . There is a plugin for this , but it has not been updated since 2012. Selfishly, this is my personal preference for you - choose this option, take on the plugin (assuming a positive answer or no answer from the original authors) and update it so that it is compatible with the latest Hibernate 4.x plugin. This will give us a good alternative to Elasticsearch.

Banning this, I think Elasticsearch is your best option.

+10
source share
Burt gave a very good description. Thanks for this.

I just want to add a short hint. Searchable plugin currently does not work with Hibernate 4.XX Try lowering your sleep mode in the project to 3.XX (sleep mode: 3.6.10.18)

So you will need: in DataSource.groovy

add / uncomment the following:

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

and delete / comment:

cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory'

at BuildConfig.groovy:

change the hibernate dependency to ": hibernate: 3.6.10.18"

It works on my machine with such changes.

Hope this helps someone.

(I found the answer here http://tiku.io/questions/4052527/does-the-searchable-plugin-work-with-grails-2-0-0-i-argue-no

+3
source share

All Articles