Annotation processor or Maven/Gradle plugins for static metamodel generation
Description
depends on
Activity
Marko BekhtaSeptember 5, 2024 at 6:56 AM
Yup, I think you’ve summarised this nicely, and there's not much to add. Thanks @Yoann Rodière !
Yoann RodièreSeptember 5, 2024 at 6:48 AM
We discussed this on Zulip: https://hibernate.zulipchat.com/#narrow/stream/132092-hibernate-search-dev/topic/Static.20metamodel.20HSEARCH-4951
Key takeaways:
Since the static metamodel may be referenced in the same Java project where it’s generated, we must generate it before, or during, compilation – otherwise compilation would fail.
Thus, Maven/Gradle plugins are unlikely solutions: we need ajavac
annotation processor.In the annotation processor, execution of application code is impossible.
Thus, when application developers expect a static metamodel, we cannot support programmatic mapping, binders and things likePropertyMappingAnnotationProcessor
as they are: we need new solutions to replace them.In the annotation processor, CDI is unavailable.
Thus, when users expect a static metamodel, we cannot support CDI instantiation of binders: application developers will need to rely on reflection-based instantiation for these components.In the annotation processor, access to Hibernate ORM’s
Metadata
objects is impossible: https://hibernate.zulipchat.com/#narrow/stream/132094-hibernate-orm-dev/topic/Hibernate.20Models.20and.20Annotation.20Processors
Thus, we need another way of inferring the Hibernate ORM metadata we need (there isn’t much).
I think that’s the gist of it – feel free to add anything I forgot @Marko Bekhta 🙂
Follows up on https://hibernate.atlassian.net/browse/HSEARCH-3319 : once the Hibernate Search DSL supports type-safe field references, we could start working on a tool to generate a static metamodel that can be used with the DSL.