alexkramer / grails-hibernate-filter

Hibernate Filters Support for Grails 3, Hibernate 5, and GORM 6
Apache License 2.0
4 stars 8 forks source link

Add support for Grails 3.3.x #3

Closed bruno-lopes closed 3 months ago

bruno-lopes commented 7 years ago

Hi. I'm trying to use Grails Hibernate Filter v0.5.2 in Grails 3.3.0.M2. When I add the dependency and try to run Grails application (grails r-a) it doesn't start because of the following error:

2017-06-15 19:30:42.771 ERROR --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Destroy method on bean with name 'org.springframework.context.annotation.internalScheduledAnnotationProcessor' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@172ca72b: startup date [Thu Jun 15 19:30:37 BRT 2017]; root of context hierarchy
        at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404)
        at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
        at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
        at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:555)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
        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 hibernatefiltertest.Application.main(Application.groovy:8)

2017-06-15 19:30:42.775 ERROR --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Destroy method on bean with name 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@172ca72b: startup date [Thu Jun 15 19:30:37 BRT 2017]; root of context hierarchy
        at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404)
        at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
        at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
        at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:555)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
        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 hibernatefiltertest.Application.main(Application.groovy:8)

2017-06-15 19:30:42.776 ERROR --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Destroy method on bean with name 'grailsApplicationPostProcessor' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@172ca72b: startup date [Thu Jun 15 19:30:37 BRT 2017]; root of context hierarchy
        at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404)
        at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
        at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
        at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:555)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
        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 hibernatefiltertest.Application.main(Application.groovy:8)

2017-06-15 19:30:42.776 ERROR --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@172ca72b: startup date [Thu Jun 15 19:30:37 BRT 2017]; root of context hierarchy
        at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404)
        at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
        at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
        at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:555)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
        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 hibernatefiltertest.Application.main(Application.groovy:8)

2017-06-15 19:30:42.979 ERROR --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in org.grails.plugin.hibernate.filter.HibernateFilterConnectionSourceFactory required a bean of type '[Ljava.lang.Class;' that could not be found.

Action:

Consider defining a bean of type '[Ljava.lang.Class;' in your configuration.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
| Error Failed to start server (Use --stacktrace to see the full trace)

I created this project in Github to demonstrate the error (https://github.com/vaidegrails/hibernateFilterErrorInGrails3.3.0.M2).

Without the dependency, the application starts normally. I tried version 0.5.1 but the error is the same. Thanks in advance!

alexkramer commented 7 years ago

I am able to reproduce this with a simple create-app and adding the plugin as you suggested. Still trying to hunt down the issue but glancing through GORM 6.1 and Grails 3.3 repos I haven't seen any changes that would explain the sudden failure.

bruno-lopes commented 7 years ago

@alexkramer, thanks for your response. I created a pull request. Could you please take a look? Thanks in advance!!!

alexkramer commented 7 years ago

From what I can tell the contract hasn't changed. Were you able to trace down why you need to explicitly pass the classes in 3.3?

alexkramer commented 7 years ago

@bruno-lopes Thanks for opening that PR. I pushed up a branch I had been working on to upgrade the project to Grails 3.3.0.RC1 to test out the fix you proposed. Please take a look as it appears that your proposal does not fix the issue. Did you try your fix in Grails 3.3.x? Because I am finding that the plugin is still broken.

I opened a PR so you can easily see the diff between the Grails 3.3.x branch of the plugin and Master: https://github.com/alexkramer/grails-hibernate-filter/pull/5

I read through a lot of the Grails Hibernate5 plugin source and am struggling to see what changed there between the implementation for GORM 6.0 and 6.1 that would have lead to this issue. I am suspecting the issue may be farther upstream.

bruno-lopes commented 7 years ago

@alexkramer, sorry for my delay in responding your question. I'm using a multi-project application, using Grails 3.3.0.M2. I didn't try that with Grails 3.3.0.RC1. Also, I didn't updated all the dependencies, like you did. I'll update to Grails 3.3.0.RC1 in order to see what happens. Thanks!

jvesouza commented 6 years ago

The same problem using version 0.5.3 and grails 3.3.2.

alexkramer commented 6 years ago

The issue is related to a change in the domain class API. Besides deprecation they removed access to some of the classes during setup. If you see the branch I have open you can see the progress I have made thus far towards removing the deprecated references. Please see the following to provide some clarity around the issue:

http://docs.grails.org/latest/guide/upgrading.html#_grails_domain_class_api_deprecated

I have been working on this (admittedly sporadically) and you can see the progress I have made on the branch and the open PR.

jvesouza commented 6 years ago

Okay, thanks for the clarifications. I need to urgently implement a filter in my application, would you have any suggestions?

phejl commented 6 years ago

What needs to be done for this to be merged?

alexkramer commented 6 years ago

I spent another morning looking into this but I still cannot figure out why the running application is unable to get access to the persistent entities. I don't have a clear understanding for what is wrong because the documentation I can find is sparse and I struggle to find another open source project that has a similar requirement -- the hibernate search plugin may have some answers but thus far they have eluded me.

To answer your question then, I do not know what is left to make this actually work and therefore merge it in. It could either be a small change that I missed or it could be the the entire plugin needs to be reworked.

Another thought that I had is why this plugin still needs to exist. Multi tenancy support in GORM for Hibernate uses hibernate filters which means the main plugin already works with them. It would seem to be not to much of an extension to support this use case.

In any event, if any of you wants to try and pull down the 3.3.x branch of this plugin and give it a go, please do! I could use some help.

gabivis commented 5 years ago

Hi. I tried to use version 0.5.4 of this plugin with my grails 3.3.9 application. However, when using multiple datasources I get an exception during startup: org.grails.datastore.mapping.model.MappingContext.getPersistentEntity(java.lang.String)] cannot be accessed before GORM has initialized

This one is triggered because at HibernateFilterBuilder, line 79 there is a call to domainClass.isRoot() and the method implementation has changed in grails 3.3.x. If I use the old implementation of the method, it works fine. So instead of calling domainClass.isRoot() I added a separate method: boolean isRoot(GrailsDomainClass domainClass) { final Class<?> superClass = domainClass.getClass().getSuperclass() DomainClassArtefactHandler.isDomainClass(superClass) ? false : true }

I know it still uses the deprecated classes but it is functional.

alexkramer commented 5 years ago

@gabivis I accepted your PR and released version 0.5.5. Please try out this version and let me know if this works for you.

gabivis commented 5 years ago

Thanks a lot Alex, it works.