Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with named analyzer used on a domain class's field #33

Open
lgrignon opened this issue Jul 18, 2017 · 11 comments
Open

Problem with named analyzer used on a domain class's field #33

lgrignon opened this issue Jul 18, 2017 · 11 comments
Assignees
Labels
Milestone

Comments

@lgrignon
Copy link
Collaborator

@betoesquivel wrote:
Other than that, I am only having an issue with building a named analyzer. I am trying to build a typeahead/autocomplete for a list of Categories with a name and a code.
I am following your example for the named analayzer with apache solr

compile group: 'org.apache.solr', name: 'solr-analysis-extras', version: '3.1.0'

Everything in application.groovy compiles

import org.apache.solr.analysis.StandardTokenizerFactory
import org.apache.solr.analysis.LowerCaseFilterFactory
import org.apache.solr.analysis.NGramFilterFactory

grails.plugins.hibernatesearch = {

    analyzer( name: 'ngram', tokenizer: StandardTokenizerFactory ) {
        filter LowerCaseFilterFactory
        filter factory: NGramFilterFactory, params: [minGramSize: 3, maxGramSize: 3]
    }

}

But when I try to use the analyzer in the class, like so:

package Tecsou.Expenses

import grails.rest.Resource

class Category {
  String name
  String code
  int sortOrder

  @Override
  String toString() {
    return name
  }

  static transients = ['text', 'value']

  String getText() {
    name
  }

  String getValue() {
    code
  }

  static search = {
    name index: 'yes', analyzer: 'ngram'
  }

  static constraints = {
    name nullable: false, size: 3..100
    code nullable: false, size: 2..10
  }
}

I get this error on compile

expenses_workers  | 2017-07-07T15:38:47.608639599Z > Building 77% > :bootRun2017-07-07 15:38:47.601 ERROR --- [           main] bernateSearchMappingContextConfiguration : cannot build session factory
expenses_workers  | 2017-07-07T15:38:47.696841794Z > Building 77% > :bootRun
expenses_workers  | 2017-07-07T15:38:47.716518108Z java.lang.NullPointerException: null
expenses_workers  | 2017-07-07T15:38:47.716568276Z         at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration$2.sessionFactoryClosed(HibernateMappingContextConfiguration.java:266)
expenses_workers  | 2017-07-07T15:38:47.716574999Z         at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryClosed(SessionFactoryObserverChain.java:61)
expenses_workers  | 2017-07-07T15:38:47.720756396Z         at org.hibernate.internal.SessionFactoryImpl.close(SessionFactoryImpl.java:756)
expenses_workers  | 2017-07-07T15:38:47.720775664Z         at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:91)
expenses_workers  | 2017-07-07T15:38:47.720780048Z         at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35)
expenses_workers  | 2017-07-07T15:38:47.720783854Z         at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:366)
expenses_workers  | 2017-07-07T15:38:47.720788278Z         at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
expenses_workers  | 2017-07-07T15:38:47.720794361Z         at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
expenses_workers  | 2017-07-07T15:38:47.720798017Z         at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration.buildSessionFactory(HibernateMappingContextConfiguration.java:274)
expenses_workers  | 2017-07-07T15:38:47.720801788Z         at grails.plugins.hibernate.search.HibernateSearchMappingContextConfiguration.buildSessionFactory(HibernateSearchMappingContextConfiguration.java:120)

If I don't use the analyzer: 'ngram'

static search = {
  name index: 'yes'
}

There is no error.

I was wondering if the issue is where I am importing the Analyzer's classes from or the version of grails I am using.

@lgrignon lgrignon self-assigned this Jul 18, 2017
@lgrignon lgrignon added this to the 2.0.4 milestone Jul 18, 2017
@lgrignon lgrignon added the bug label Jul 18, 2017
@betoesquivel
Copy link

Thanks for the follow-up! Let me know if you need any more data.

I'll have another go at this later in the day, since I still need this, and keep you posted.

@lgrignon lgrignon changed the title Problem with named analyzer used globally on a domain class Problem with named analyzer used on a domain class's field Jul 19, 2017
@lgrignon
Copy link
Collaborator Author

It was indeed the solr library which was inappropriate for hibernate search, you have to use the lucene analyzers. I just pushed a new version of the example to show you how to use analyzers with this plugin:
https://github.com/lgrignon/grails3-quick-start

Basically, you have to use those classes:

import org.apache.lucene.analysis.standard.StandardTokenizerFactory
import org.apache.lucene.analysis.core.LowerCaseFilterFactory
import org.apache.lucene.analysis.ngram.NGramFilterFactory

You can find the details here:
https://github.com/lgrignon/grails3-quick-start/blob/master/grails-app/conf/application.groovy#L71

Please tell me if it is ok for you and I will close.

@betoesquivel
Copy link

betoesquivel commented Jul 19, 2017

Excellent! I will have a look right now.

@betoesquivel
Copy link

betoesquivel commented Jul 19, 2017

I tried installing with this configuration:

gradle.build
    // Search plugin dependencies
    compile "org.grails.plugins:hibernate5:6.1.3"
    compile 'org.grails.plugins:cache'
    compile "org.hibernate:hibernate-core:5.2.9.Final"
    compile "org.hibernate:hibernate-ehcache:5.2.9.Final"
    compile "org.hibernate:hibernate-entitymanager:5.2.9.Final"

    // Search plugins
    compile 'org.grails.plugins:hibernate-search:2.1.1'
application.groovy

import org.apache.lucene.analysis.standard.StandardTokenizerFactory
import org.apache.lucene.analysis.core.LowerCaseFilterFactory
import org.apache.lucene.analysis.ngram.NGramFilterFactory

//...

grails.plugins.hibernatesearch = {

    rebuildIndexOnStart false
    throwOnEmptyQuery false

    analyzer( name: 'ngram', tokenizer: StandardTokenizerFactory ) {
      filter LowerCaseFilterFactory
      filter(NGramFilterFactory) {
        param 'minGramSize', 3
        param 'maxGramSize', 3
      }
    }

}

and I got this on compile: name_workers | 2017-07-19T15:47:38.916702611Z | Error Error initializing classpath: Could not find org.grails.plugins:hibernate-search:2.1.1.

Then I tried downgrading to hibernate-search:2.1.0 (the one I had before), and got this on build:

name_api  | 2017-07-19T15:57:37.296378892Z > Building 77% > :bootRun2017-07-19 15:57:37.280 ERROR --- [           main] o.s.boot.SpringApplication               : Application startup failed
name_api  | 2017-07-19T15:57:37.385617748Z > Building 77% > :bootRun
name_api  | 2017-07-19T15:57:37.385658081Z java.lang.IllegalStateException: Either class [Package.Name.Category] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.

Which based on this I assumed was a problem with my application.yml GORM configuration.

My project setup is like so:

tree at the src/ folder in my project
├── Package.Name.Api
│   ├── build-dk
│   ├── build.gradle
│   ├── dev.sh
│   ├── gradle
│   ├── gradle.properties
│   ├── gradlew
│   ├── gradlew.bat
│   ├── grails-app
│   ├── grailsw
│   ├── grailsw.bat
│   ├── grails-wrapper.jar
│   ├── README.md
│   ├── settings.gradle
│   ├── src
│   └── Package.Name.Api.iml
├── Package.Name.Domain
│   ├── build-dk
│   ├── build.gradle
│   ├── gradle
│   ├── gradle.properties
│   ├── gradlew
│   ├── gradlew.bat
│   ├── grails-app
│   ├── grailsw
│   ├── grailsw.bat
│   ├── grails-wrapper.jar
│   ├── README.md
│   ├── settings.gradle
│   ├── src
│   └── Package.Name.Domain.iml
└── Package.Name.Workers
    ├── build-dk
    ├── build.gradle
    ├── dev.sh
    ├── gradle
    ├── gradle.properties
    ├── gradlew
    ├── gradlew.bat
    ├── grails-app
    ├── grailsw
    ├── grailsw.bat
    ├── grails-wrapper.jar
    ├── hs_err_pid143.log
    ├── libs
    ├── quickScripts
    ├── README.md
    ├── settings.gradle
    ├── src
    └── Package.Name.Workers.iml

where the Domain contains the application.groovy and the build.gradle that I am configuring, and the Workers and Api both depend on Domain with these lines in their build.gradle's

grails {
    plugins {
        compile project(':Package.Name.Domain')
    }
}

So to solve the GORM configuration issue, I tried setting my application.yml hibernate config exactly like yours in the example project. I didn't know if I had to set this in all of my 3 projects, the one with the Domain classes and the Api and Workers which depend on it as a plugin, so I added it on all 3.

{Api,Workers,Domain}/grails-app/conf/application.yml
hibernate:
    naming_strategy: org.hibernate.cfg.DefaultNamingStrategy
    cache:
        use_second_level_cache: true
        use_query_cache: true
        provider_class: net.sf.ehcache.hibernate.EhCacheProvider
        region:
          factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
    search:
        default:
          indexmanager: near-real-time
          indexBase: '/indexes'
          directory_provider: filesystem

Note: For each of this attempts I have been deleting /.gradle and /build folders to remove any cached dependencies just in case.

I also attempted deleting my filesystem /indexes folder

name_api  | 2017-07-19T16:30:02.437265663Z > Building 77% > :bootRun2017-07-19 16:30:02.430 ERROR --- [           main] bernateSearchMappingContextConfiguration : cannot build session factory
name_api  | 2017-07-19T16:30:02.528851594Z > Building 77% > :bootRun
name_api  | 2017-07-19T16:30:02.528892190Z java.lang.NullPointerException: null
name_api  | 2017-07-19T16:30:02.528904177Z         at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration$2.sessionFactoryClosed(HibernateMappingContextConfiguration.java:266)
name_api  | 2017-07-19T16:30:02.528910133Z         at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryClosed(SessionFactoryObserverChain.java:61)
name_api  | 2017-07-19T16:30:02.528914481Z         at org.hibernate.internal.SessionFactoryImpl.close(SessionFactoryImpl.java:756)
name_api  | 2017-07-19T16:30:02.528918450Z         at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:91)
name_api  | 2017-07-19T16:30:02.528922759Z         at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35)
name_api  | 2017-07-19T16:30:02.528926951Z         at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:366)
name_api  | 2017-07-19T16:30:02.528931441Z         at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
name_api  | 2017-07-19T16:30:02.528935850Z         at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
name_api  | 2017-07-19T16:30:02.528939842Z         at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration.buildSessionFactory(HibernateMappingContextConfiguration.java:274)
name_api  | 2017-07-19T16:30:02.528944065Z         at grails.plugins.hibernate.search.HibernateSearchMappingContextConfiguration.buildSessionFactory(HibernateSearchMappingContextConfiguration.java:120)
name_api  | 2017-07-19T16:30:02.528948309Z         at org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory.create(HibernateConnectionSourceFactory.java:86)
name_api  | 2017-07-19T16:30:02.528952831Z         at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:38)
name_api  | 2017-07-19T16:30:02.528957384Z         at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:22)
name_api  | 2017-07-19T16:30:02.528962270Z         at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:64)
name_api  | 2017-07-19T16:30:02.528982284Z         at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:52)
name_api  | 2017-07-19T16:30:02.528989938Z         at org.grails.datastore.mapping.core.connections.ConnectionSourcesInitializer.create(ConnectionSourcesInitializer.groovy:24)
name_api  | 2017-07-19T16:30:02.528994438Z         at org.grails.orm.hibernate.HibernateDatastore.<init>(HibernateDatastore.java:170)
name_api  | 2017-07-19T16:30:02.528998562Z         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
name_api  | 2017-07-19T16:30:02.529006244Z         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
name_api  | 2017-07-19T16:30:02.529011014Z         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
name_api  | 2017-07-19T16:30:02.529014872Z         at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
name_api  | 2017-07-19T16:30:02.529018634Z         at org.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:1075)
name_api  | 2017-07-19T16:30:02.529022594Z         at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
name_api  | 2017-07-19T16:30:02.529026450Z         at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
name_api  | 2017-07-19T16:30:02.529030335Z         at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271)
name_api  | 2017-07-19T16:30:02.529033936Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
name_api  | 2017-07-19T16:30:02.529335884Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
name_api  | 2017-07-19T16:30:02.529362443Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
name_api  | 2017-07-19T16:30:02.529370157Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
name_api  | 2017-07-19T16:30:02.529374687Z         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
name_api  | 2017-07-19T16:30:02.529378613Z         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
name_api  | 2017-07-19T16:30:02.529382364Z         at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
name_api  | 2017-07-19T16:30:02.529386827Z         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
name_api  | 2017-07-19T16:30:02.529393881Z         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
name_api  | 2017-07-19T16:30:02.529397695Z         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
name_api  | 2017-07-19T16:30:02.529411336Z         at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:648)
name_api  | 2017-07-19T16:30:02.529416180Z         at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145)
name_api  | 2017-07-19T16:30:02.529420212Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
name_api  | 2017-07-19T16:30:02.529423786Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
name_api  | 2017-07-19T16:30:02.529427438Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:923)
name_api  | 2017-07-19T16:30:02.529431007Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:804)
name_api  | 2017-07-19T16:30:02.529436487Z         at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:558)
name_api  | 2017-07-19T16:30:02.529440427Z         at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:432)
name_api  | 2017-07-19T16:30:02.529444336Z         at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:395)
name_api  | 2017-07-19T16:30:02.529447944Z         at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:220)
name_api  | 2017-07-19T16:30:02.529451869Z         at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1260)
name_api  | 2017-07-19T16:30:02.529455685Z         at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1180)
name_api  | 2017-07-19T16:30:02.529968844Z         at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1096)
name_api  | 2017-07-19T16:30:02.529992468Z         at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
name_api  | 2017-07-19T16:30:02.529998080Z         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:659)
name_api  | 2017-07-19T16:30:02.530002460Z         at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
name_api  | 2017-07-19T16:30:02.530006062Z         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
name_api  | 2017-07-19T16:30:02.530010062Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
name_api  | 2017-07-19T16:30:02.530013869Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
name_api  | 2017-07-19T16:30:02.530029307Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
name_api  | 2017-07-19T16:30:02.530033738Z         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
name_api  | 2017-07-19T16:30:02.530037105Z         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
name_api  | 2017-07-19T16:30:02.530040481Z         at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
name_api  | 2017-07-19T16:30:02.530043544Z         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
name_api  | 2017-07-19T16:30:02.530046984Z         at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372)
name_api  | 2017-07-19T16:30:02.530050718Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
name_api  | 2017-07-19T16:30:02.530056538Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
name_api  | 2017-07-19T16:30:02.530634800Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
name_api  | 2017-07-19T16:30:02.530667494Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
name_api  | 2017-07-19T16:30:02.530675990Z         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
name_api  | 2017-07-19T16:30:02.530680770Z         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
name_api  | 2017-07-19T16:30:02.530685083Z         at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
name_api  | 2017-07-19T16:30:02.530689437Z         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
name_api  | 2017-07-19T16:30:02.530693408Z         at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92)
name_api  | 2017-07-19T16:30:02.530697629Z         at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:102)
name_api  | 2017-07-19T16:30:02.530701746Z         at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:88)
name_api  | 2017-07-19T16:30:02.530712377Z         at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103)
name_api  | 2017-07-19T16:30:02.530717257Z         at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:248)
name_api  | 2017-07-19T16:30:02.530721461Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1037)
name_api  | 2017-07-19T16:30:02.530737419Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1011)
name_api  | 2017-07-19T16:30:02.530741575Z         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:473)
name_api  | 2017-07-19T16:30:02.532629063Z         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
name_api  | 2017-07-19T16:30:02.532663998Z         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
name_api  | 2017-07-19T16:30:02.532671554Z         at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
name_api  | 2017-07-19T16:30:02.532675601Z         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
name_api  | 2017-07-19T16:30:02.532680468Z         at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:235)
name_api  | 2017-07-19T16:30:02.532685688Z         at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:702)
name_api  | 2017-07-19T16:30:02.532690508Z         at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:527)
name_api  | 2017-07-19T16:30:02.532695263Z         at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
name_api  | 2017-07-19T16:30:02.532700023Z         at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
name_api  | 2017-07-19T16:30:02.532704958Z         at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372)
name_api  | 2017-07-19T16:30:02.532709557Z         at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
name_api  | 2017-07-19T16:30:02.532714365Z         at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
name_api  | 2017-07-19T16:30:02.532718716Z         at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
name_api  | 2017-07-19T16:30:02.532722937Z         at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
name_api  | 2017-07-19T16:30:02.532727067Z         at grails.boot.GrailsApp$run.call(Unknown Source)
name_api  | 2017-07-19T16:30:02.532731772Z         at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
name_api  | 2017-07-19T16:30:02.532736581Z         at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
name_api  | 2017-07-19T16:30:02.532740823Z         at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
name_api  | 2017-07-19T16:30:02.532745275Z         at Package.Name.Application.main(Application.groovy:8)
name_api  | 2017-07-19T16:30:02.532749930Z
name_api  | 2017-07-19T16:30:02.532757324Z 2017-07-19 16:30:02.458 ERROR --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Destroy method on bean with name 'org.springframework.context.annotation.internalScheduledAnnotationProcessor' threw an exception
name_api  | 2017-07-19T16:30:02.532763076Z
name_api  | 2017-07-19T16:30:02.532784587Z java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5496c165: startup date [Wed Jul 19 16:29:34 UTC 2017]; root of context hierarchy
name_api  | 2017-07-19T16:30:02.532791769Z         at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404)
name_api  | 2017-07-19T16:30:02.532796420Z         at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
name_api  | 2017-07-19T16:30:02.532801052Z         at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
name_api  | 2017-07-19T16:30:02.532805806Z         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
name_api  | 2017-07-19T16:30:02.532810352Z         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
name_api  | 2017-07-19T16:30:02.532814628Z         at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
name_api  | 2017-07-19T16:30:02.532819582Z         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
name_api  | 2017-07-19T16:30:02.532823972Z         at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
name_api  | 2017-07-19T16:30:02.532828458Z         at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033)
name_api  | 2017-07-19T16:30:02.532833113Z         at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:555)
name_api  | 2017-07-19T16:30:02.532837367Z         at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
name_api  | 2017-07-19T16:30:02.532841674Z         at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
name_api  | 2017-07-19T16:30:02.532846166Z         at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372)
name_api  | 2017-07-19T16:30:02.532852535Z         at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
name_api  | 2017-07-19T16:30:02.532857834Z         at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
name_api  | 2017-07-19T16:30:02.532862143Z         at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
name_api  | 2017-07-19T16:30:02.532866336Z         at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
name_api  | 2017-07-19T16:30:02.532870692Z         at grails.boot.GrailsApp$run.call(Unknown Source)
name_api  | 2017-07-19T16:30:02.532875192Z         at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
name_api  | 2017-07-19T16:30:02.532879877Z         at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
name_api  | 2017-07-19T16:30:02.532883932Z         at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
name_api  | 2017-07-19T16:30:02.532893121Z         at Package.Name.Application.main(Application.groovy:8)

This error is quite obscure in that it looks like it is a problem with the xml config, but I don't know how to port this config or something like this to my application.yml. My datastore is working without hibernate-search. In fact, it was working with hibernate-search without the named analyzers. So I believe the dataStore is correct, it must be a problem maybe with the org.hibernate.dialect.MySQLDialect? I am using mariadb as a backend.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/tutorialDB</property>
    <property name="hibernate.connection.username">dummyuser</property>
    <property name="hibernate.connection.password">dummyuser</property>
    <property name="hibernate.hbm2ddl.auto">update</property> 
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="show_sql">true</property>
    <mapping class="com.vanilla.entity.Student" />
</session-factory>
</hibernate-configuration>

@betoesquivel
Copy link

betoesquivel commented Jul 19, 2017

On further exploration with a teammate (@erichmx), we noticed that it sometimes works and sometimes doesn't. So there could be a race condition somewhere.

@erichmx
Copy link

erichmx commented Jul 19, 2017

@lgrignon it is very weird, I can now tell you that it is not related to the analyzer, just having a name index: 'yes' leads to the error most of the times, but sometimes it starts without error. Most puzzling part being that those times when the project starts succesfuly I don't see a message bernateSearchMappingContextConfiguration : configuration extension for hibernate search: grails.plugins.hib

And also I don't understand why the sessionFactoryClosed is being called???

My main hypothesis is that the sessionFactoryClosed is being called when the serviceRegistry is still null

This is part of the log of a successful run:

 o.h.v.internal.engine.ConfigurationImpl  : HV000002: Ignoring XML configuration.
 trationDelegate$BeanPostProcessorChecker : Bean 'messageSource' of type [org.grails.spring.context.support.PluginAwareResourceBundleMessageSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 o.h.v.internal.engine.ConfigurationImpl  : HV000002: Ignoring XML configuration.
 trationDelegate$BeanPostProcessorChecker : Bean 'mongoDatastore' of type [org.grails.datastore.mapping.mongo.MongoDatastore] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 trationDelegate$BeanPostProcessorChecker : Bean 'hibernateConnectionSourceFactory' of type [org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 trationDelegate$BeanPostProcessorChecker : Bean 'dataSourceUnproxied' of type [org.apache.tomcat.jdbc.pool.DataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 trationDelegate$BeanPostProcessorChecker : Bean 'dataSourceLazy' of type [org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 trationDelegate$BeanPostProcessorChecker : Bean 'dataSource' of type [org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.9.Final}
 org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
 o.h.v.internal.engine.ConfigurationImpl  : HV000002: Ignoring XML configuration.
 o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
 org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
 n.s.ehcache.config.ConfigurationFactory  : No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in the classpath: jar:file:/home/ehauske/.gradle/caches/modules-2/files-2.1/net.sf.ehcache/ehcache/2.10.3/cf74f9a4a049f181833b147a1d9aa62159c9d01d/ehcache-2.10.3.jar!/ehcache-failsafe.xml
 o.h.c.e.AbstractEhcacheRegionFactory     : HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.spi.UpdateTimestampsCache]; using defaults.
 o.h.cache.spi.UpdateTimestampsCache      : HHH000250: Starting update timestamps cache at region: org.hibernate.cache.spi.UpdateTimestampsCache
 o.h.c.e.AbstractEhcacheRegionFactory     : HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.internal.StandardQueryCache]; using defaults.
 o.h.cache.internal.StandardQueryCache    : HHH000248: Starting query cache at region: org.hibernate.cache.internal.StandardQueryCache
 org.hibernate.search.engine.Version      : HSEARCH000034: Hibernate Search 5.7.0.Final
 .g.o.h.GrailsHibernateTransactionManager : Using DataSource [org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy@78b2d29e] of Hibernate SessionFactory for HibernateTransactionManager
 o.h.v.internal.engine.ConfigurationImpl  : HV000002: Ignoring XML configuration.
 o.s.b.f.xml.XmlBeanDefinitionReader      : Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
 o.s.jdbc.support.SQLErrorCodesFactory    : SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]
 o.h.v.internal.engine.ConfigurationImpl  : HV000002: Ignoring XML configuration.
 o.h.v.internal.engine.ConfigurationImpl  : HV000002: Ignoring XML configuration.
 trationDelegate$BeanPostProcessorChecker : Bean 'hibernateDatastore' of type [org.grails.orm.hibernate.HibernateDatastore] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$dc322c01] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
 o.apache.catalina.core.StandardService   : Starting service Tomcat
 org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.13
 o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
 o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 17406 ms
 o.s.b.GenericTypeAwarePropertyDescriptor : Invalid JavaBean property 'exceptionMappings' being accessed! Ambiguous write methods found next to actually used [public void grails.plugin.springsecurity.web.authentication.AjaxAwareAuthenticationFailureHandler.setExceptionMappings(java.util.List)]: [public void org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler.setExceptionMappings(java.util.Map)]

And the correpondent part of a failed run log:

 o.h.v.internal.engine.ConfigurationImpl  : HV000002: Ignoring XML configuration.
 trationDelegate$BeanPostProcessorChecker : Bean 'messageSource' of type [org.grails.spring.context.support.PluginAwareResourceBundleMessageSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 o.h.v.internal.engine.ConfigurationImpl  : HV000002: Ignoring XML configuration.
 trationDelegate$BeanPostProcessorChecker : Bean 'mongoDatastore' of type [org.grails.datastore.mapping.mongo.MongoDatastore] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 trationDelegate$BeanPostProcessorChecker : Bean 'hibernateConnectionSourceFactory' of type [org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 trationDelegate$BeanPostProcessorChecker : Bean 'dataSourceUnproxied' of type [org.apache.tomcat.jdbc.pool.DataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 trationDelegate$BeanPostProcessorChecker : Bean 'dataSourceLazy' of type [org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 trationDelegate$BeanPostProcessorChecker : Bean 'dataSource' of type [org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.9.Final}
 org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
 o.h.v.internal.engine.ConfigurationImpl  : HV000002: Ignoring XML configuration.
*********************** THIS ONE IS NOT LOGGED IN A SUCCESFUL RUN ****
 bernateSearchMappingContextConfiguration : configuration extension for hibernate search: grails.plugins.hibernate.search.HibernateSearchMappingContextConfiguration@1d686622
 o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
 org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
 n.s.ehcache.config.ConfigurationFactory  : No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in the classpath: jar:file:/home/ehauske/.gradle/caches/modules-2/files-2.1/net.sf.ehcache/ehcache/2.10.3/cf74f9a4a049f181833b147a1d9aa62159c9d01d/ehcache-2.10.3.jar!/ehcache-failsafe.xml
 o.h.c.e.AbstractEhcacheRegionFactory     : HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.spi.UpdateTimestampsCache]; using defaults.
 o.h.cache.spi.UpdateTimestampsCache      : HHH000250: Starting update timestamps cache at region: org.hibernate.cache.spi.UpdateTimestampsCache
 o.h.c.e.AbstractEhcacheRegionFactory     : HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.internal.StandardQueryCache]; using defaults.
 o.h.cache.internal.StandardQueryCache    : HHH000248: Starting query cache at region: org.hibernate.cache.internal.StandardQueryCache
 org.hibernate.search.engine.Version      : HSEARCH000034: Hibernate Search 5.7.0.Final
 o.h.s.s.impl.DirectoryProviderHelper     : HSEARCH000041: Index directory not found, creating: '/indexes'
 : cannot build session factory
java.lang.NullPointerException: null
        at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration$2.sessionFactoryClosed(HibernateMappingContextConfiguration.java:266)
        at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryClosed(SessionFactoryObserverChain.java:61)
        at org.hibernate.internal.SessionFactoryImpl.close(SessionFactoryImpl.java:756)
        at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:91)
        at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:366)
        at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
        at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration.buildSessionFactory(HibernateMappingContextConfiguration.java:274)
        at grails.plugins.hibernate.search.HibernateSearchMappingContextConfiguration.buildSessionFactory(HibernateSearchMappingContextConfiguration.java:120)
        at org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory.create(HibernateConnectionSourceFactory.java:86)
        at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:38)
        at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:22)
        at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:64)
        at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:52)
        at org.grails.datastore.mapping.core.connections.ConnectionSourcesInitializer.create(ConnectionSourcesInitializer.groovy:24)
        at org.grails.orm.hibernate.HibernateDatastore.<init>(HibernateDatastore.java:170)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:1075)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)

@lgrignon
Copy link
Collaborator Author

Could you provide a link to a github with your full project please? It would be perfect to reproduce.

@lgrignon
Copy link
Collaborator Author

@erichmx
An insight: the sessionFactoryClosed is called whenever Hibernate initialization fails, and if ever it is called before serviceRegistry manages to be instantiated, the original exception is just swallowed, this is really annoying.
You may try to display it by changing the log level of hibernate and gorm but I don"t think it will be printed.
Please tell me if you could give me more intels

Thanks again for reporting

@erichmx
Copy link

erichmx commented Jul 27, 2017

@lgrignon, here is more info. I updated to hibernate-search 2.1.1. Still the same exception.

Looking more closely at the stacktrace I see a potential problem: org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated is the one closing the sessionFactory!! and without logging why. My hypothesis is that is trying to access factoryImplementor.getServiceRegistry() before it is created, hence the race condition. Does it make sense?

Caused by: java.lang.NullPointerException: null
        at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration$2.sessionFactoryClosed(HibernateMappingContextConfiguration.java:266)
        at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryClosed(SessionFactoryObserverChain.java:61)
        at org.hibernate.internal.SessionFactoryImpl.close(SessionFactoryImpl.java:756)
-->>    at  org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:91)
        at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:366)
        at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
        at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration.buildSessionFactory(HibernateMappingContextConfiguration.java:274)
        at grails.plugins.hibernate.search.HibernateSearchMappingContextConfiguration.super$3$buildSessionFactory(HibernateSearchMappingContextConfiguration.groovy)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1218)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:152)
        at grails.plugins.hibernate.search.HibernateSearchMappingContextConfiguration.buildSessionFactory(HibernateSearchMappingContextConfiguration.groovy:150)
        at org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory.create(HibernateConnectionSourceFactory.java:86)
        at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:38)
        at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:22)
        at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:64)
        at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:52)
        at org.grails.datastore.mapping.core.connections.ConnectionSourcesInitializer.create(ConnectionSourcesInitializer.groovy:24)
        at org.grails.orm.hibernate.HibernateDatastore.<init>(HibernateDatastore.java:170)

	@Override
	public void sessionFactoryCreated(SessionFactory factory) {
		boolean failedBoot = true;
		try {
			final SessionFactoryImplementor factoryImplementor = (SessionFactoryImplementor) factory;
			HibernateSessionFactoryService sessionService = new DefaultHibernateSessionFactoryService( factory );
			if ( extendedIntegrator == null ) {
				SearchIntegrator searchIntegrator = new SearchIntegratorBuilder()
						.configuration( new SearchConfigurationFromHibernateCore( metadata, configurationService, classLoaderService, sessionService ) )
						.buildSearchIntegrator();
				extendedIntegrator = searchIntegrator.unwrap( ExtendedSearchIntegrator.class );
			}

			Boolean enableJMX = configurationService.getSetting( Environment.JMX_ENABLED, BOOLEAN, Boolean.FALSE );
			if ( enableJMX.booleanValue() ) {
				indexControlMBeanName =
						enableIndexControlBean( configurationService, extendedIntegrator );
			}
			listener.initialize( extendedIntegrator );
			//Register the SearchFactory in the ORM ServiceRegistry (for convenience of lookup)
-->>			factoryImplementor.getServiceRegistry().getService( SearchFactoryReference.class ).initialize( extendedIntegrator );
			failedBoot = false;
		}
		finally {
			if ( failedBoot ) {
-->>				factory.close();
			}
		}
	}
   public SessionFactory buildSessionFactory() throws HibernateException {
...
        setSessionFactoryObserver(new SessionFactoryObserver() {
            private static final long serialVersionUID = 1;
            public void sessionFactoryCreated(SessionFactory factory) {}
            public void sessionFactoryClosed(SessionFactory factory) {
-->>                ((ServiceRegistryImplementor)serviceRegistry).destroy();
            }
        });

        StandardServiceRegistryBuilder standardServiceRegistryBuilder = createStandardServiceRegistryBuilder(bootstrapServiceRegistry)
                                                                                    .applySettings(getProperties());

        StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
        sessionFactory = super.buildSessionFactory(serviceRegistry);
-->>        this.serviceRegistry = serviceRegistry;

        return sessionFactory;

cc @betoesquivel

@lgrignon
Copy link
Collaborator Author

The problem with their superb exception handling is that we cannot know what root exception caused this rollback process. Did you try running grails in debug and debugging in Eclipse with Hibernate & Hibernate search sources attached?

@lgrignon
Copy link
Collaborator Author

Hello again, did you manage to fix your error?
Could you try the last version of the plugin for Grails 3.2 ? https://github.com/mathpere/grails-hibernate-search-plugin/releases/tag/2.1.2

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants