jamesfredley commented on PR #15183: URL: https://github.com/apache/grails-core/pull/15183#issuecomment-3854397217
### Why GormEntity Works but HibernateEntity Didn't The issue is **NOT** that Groovy 5 prohibits static methods in traits. `GormEntity` has 87+ static methods and works fine. The issue is **joint compilation with Java files that directly import the trait**. | Trait | Module | Static Methods | Java Files Import It? | Result | |-------|--------|----------------|----------------------|--------| | `GormEntity` | grails-datamapping-core | 87 | **No** | Works | | `HibernateEntity` | grails-data-hibernate5-core | 5 | **Yes** (`HibernateMappingContext.java`) | Fails | | `MongoEntity` | grails-data-mongodb | 18 | No | Works | | `Neo4jEntity` | grails-data-neo4j | 10 | No | Works | ### The Technical Problem When a **Java file in the same module** imports a Groovy trait with static methods that return generic type parameters (`D`), the Groovy stub generator creates invalid Java code: ```java // Generated stub (INVALID Java) @groovy.transform.Generated() static java.util.List<D> findAllWithSql(java.lang.CharSequence sql); // ^ ERROR: non-static type variable D // cannot be referenced from static context ``` In Java, you cannot use a class-level type parameter (`D`) in a static method signature. The Groovy trait works because Groovy handles this differently at runtime, but the Java stub generator doesn't account for this. --- ## The Solution ### Approach: Remove Java Import via Reflection Instead of removing the static methods from the trait, we modified `HibernateMappingContext.java` to load `HibernateEntity` via reflection, avoiding the need for Java stubs: Updated commit with this change: https://github.com/apache/grails-core/commit/425d2da3b633fa471ad64dbb21a92c1327a5268b @jdaugherty these commits are not indented to be part of the real PR they are just a map for the real commit, it identifies everything that breaks trying to build. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
