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

Unsupported mapWith="none" #8

Closed tmysik closed 6 years ago

tmysik commented 6 years ago

This is maybe not a bug or maybe more a question but grails-hibernate-filter version 0.5.3 (the latest version currently available) fails on our - Grails version 3.2.9 - domain classes without DB tables (mapWith = "none"). I believe that such domain classes should be ignored, right? We are using them only for ElasticSearch.

Thanks.

alexkramer commented 6 years ago

Would you be able to provide a small code example or a snippet of the exception that you are seeing?

tmysik commented 6 years ago

Will try to deliver a sample project later if needed. Basically, the steps should be:

Result: no exception as expected, the given Test class is ignored during validation by Hibernate

Actual result: DB schema validation fails on the given domain class (which should be ignored); sample exception see e.g. here (exception message adjusted) Expected result: no exception as before

I tried to look at it a bit and the problem seems to be here; if I comment/remove the line hibernateConnectionSourceFactory(HibernateFilterConnectionSourceFactory), no exception during DB schema validation occurs.

Thanks!

alexkramer commented 6 years ago

The line you referenced is the installation point of the plugin. If you remove that then you are disabling the plugin entirely.

Out of curiosity, why would you want to create a domain class that isn't persistent? Can it not be moved to src/groovy? Is it because that is what is required by Elastic Search? (I have never implemented Elastic Search in Grails)

The stacktrace you provided is interesting because it looks like it might hit a snag in the hibernate source code -- prior to it hitting any of the plugin logic. If I have some time this weekend, I will see if I can replicate this issue. Maybe GORM is filtering these classes prior to instantiating the hibernate connection factory. I will have to peruse the source code.

A couple of additional points for clarity that would be useful to me -- what version of GORM are you using? And can you confirm that your mapWith = "none" classes do not have hibernate filter closures defined?

tmysik commented 6 years ago

First of all, thanks for your answer.

The line you referenced is the installation point of the plugin. If you remove that then you are disabling the plugin entirely.

Yes, that sounds like the reason why it works :)

Out of curiosity, why would you want to create a domain class that isn't persistent? Can it not be moved to src/groovy? Is it because that is what is required by Elastic Search? (I have never implemented Elastic Search in Grails)

Exactly. We use some Grails plugin that enables to store Domain classes to ES directly. These classes have static mapWith = "none", of course.

The stacktrace you provided is interesting because it looks like it might hit a snag in the hibernate source code -- prior to it hitting any of the plugin logic. If I have some time this weekend, I will see if I can replicate this issue. Maybe GORM is filtering these classes prior to instantiating the hibernate connection factory. I will have to peruse the source code.

That would be great.

A couple of additional points for clarity that would be useful to me -- what version of GORM are you using? And can you confirm that your mapWith = "none" classes do not have hibernate filter closures defined?

Grails version: 3.2.9 GORM version: 6.0.10 I can confirm that none of these ES classes has defined any hibernate filter.

Thank you for your time.

alexkramer commented 6 years ago

I cannot reproduce this issue. I added a domain class to the example project in the plugin that includes static mapWith = "none" and the project starts up without errors.

tmysik commented 6 years ago

@alexkramer Thanks a lot! In such a case, I will try to investigate what could be the cause in our case and let you know (or try to create a sample project).

Thanks again for your time.

phejl commented 6 years ago

It seems that in current implementation all classes (of type Class) spring can find are injected to the constructor of HibernateFilterConnectionSourceFactory. However the source factory (the default one) coming from hibernate (see grails.plugin.hibernate.HibernateGrailsPlugin) explicitly search for and inject only the relevant classes. That's the difference and cause of later problems with validation I believe.

alexkramer commented 6 years ago

@phejl Thanks for the example project. What is interesting is that I cannot reproduce the issue when using this project -- I would have expected by adding a similar domain class to the example project the build would fail but I wasn't able to make that happen. In any event I pushed your changes and verified that pulling in the new version 0.5.4 allows the example project you provided to start up successfully.

phejl commented 6 years ago

@alexkramer Thanks for merging this. Is there any chance for a release containing this? Thanks in advance.

The example project fails on the startup not during the build - it fails during the validation so it won't ever happen if the dbCreate in application.yml is update or create-drop. Note the configured dbCreate is set to validate in order to this be manifested.

alexkramer commented 6 years ago

@phejl The new version has been released already. If you update your dependency to 0.5.4 you should get the revised package.

phejl commented 6 years ago

@alexkramer Awesome! Thank you.