Updating from Grails 3 to Grails 4 - getting lots of "bytecode enhancement failed" exceptions now
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Expected Behaviour / Actual Behaviour
We have several domains, some with inheritance, many with traits, lots and lots of hasManys. Often we try to serialize them in some way, for JSON responses or when we convert them to a Map in order to index them as Documents into Elasticsearch, during which we call referenced domains, fetch their name and status etc, use where-statements, etc etc.. And then for some domains, the exception appears `bytecode enhancement failed` ([stacktrace](https://gist.github.com/dularion/8398273d5a213832465149f03f21b64e)), and it did not appear Grails 3. We noted that this most often happens during where-statements (but not all of them) or when calling nested properties on referenced domains (but not all of them). However, when it happens for a certain Domain, it happens consistently. It also points us to a line within that Domain, but even if we remove that for test-purposes, it just goes to the next line and the next until, if there is no property left to point to, it just shows a generic version of the same exception.
Do you know what might cause this? we found [here](https://docs.jboss.org/hibernate/orm/5.0/topical/html/bytecode/BytecodeEnhancement.html) that that if we add `@ManagedEntity` it resolves the issue, but are we supposed to add that to every domain? how likely is that to break other stuff? We couldn't find a lot of info on this Annotation and we are scared of using it in our Production Applikation before we understand it better. Also, Its not added in Domains in new grails 4 projects using the create-app command, either, so why does our application break without it?
### Steps to Reproduce
Unfortunately, we have not been able to reproduce this on in a new & fresh Grails4 Project, if necessary, we can try to piece something together, but it wont be easy, because it is happening for a pretty large application of ours that has many moving bits and pieces, all of which could have an impact on this.
### Environment Information
- **Operating System**: Mac / Linux / Windows (different developers can reproduce it on their OS)
- grailsVersion=4.1.0.M2
- groovyVersion=3.0.5
- gorm.version=7.1.0.M3
- gradleWrapperVersion=5.6
- **JDK Version:** JDK8
We really hope you can shed some light on this issue, and maybe point us to some docs on ManagedEntity that explain why that might be necessary in certain cases
Contributor guide
Research direction
Start with the linked stacktrace and the affected domain referenced by it; compare the failing where-statements and nested-property serialization paths under Grails 3 and Grails 4. Check whether @ManagedEntity changes the behavior across the listed Grails, Groovy, and GORM versions. Done requires a minimal reproducer or a confirmed cause with guidance on whether domains need the annotation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100