-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support new Hibernate 6.3 syntax for type-safe queries #36168
Comments
The need for this is now much more acute, since Jakarta Data is almost here. What used to be called the "JPA Static Metamodel Generator" (#29068) is now so much more. I have tested Hibernate Data Repositories with Quarkus, and it works perfectly (modulo a bug in how Quarkus handles But, in IntelliJ, the processor does not get run on code changes when in dev mode, and so I have to explicitly request a build by hitting ⌘\ every time. That's not so awful, but users aren't going to know to do it, and it's something they're not used to needing in Quarkus. |
In fairness, I just tried a Maven project and it does work there, apparenlty perfectly, I guess because of the work @FroMage already did. |
Scratch that, actually in Maven it's way worse, because if I try to add a
and I have to delete the method to recover. This doesn't happen with Gradle. |
This turned out to be a problem on my side. The |
I wonder how the fact that Hibernate 6.6.0.Final includes a complete implementation of the Jakarta Data 1.0 Release impacts this issue. Hibernate 6.6.0.Final and is available since Quarkus 3.14.0:
|
Jakarta Data is different from Hibernate ORM's own syntax. Jakarta Data focuses on stateless sessions, while Hibernate ORM's type-safe queries work with an @FroMage is working on an integration in Panache, that would hopefull unify all this. But AFAIK it's not ready yet. In the meantime you should already be able to use Jakarta Data in Quarkus, as it's a purely build-time (annotation processor) thing. |
Hey @pipinet. Please open a GitHub Discussion instead of hijacking this issue: it's bad form. |
Description
Hibernate 6.3 comes with experimental support for mapping HQL/SQL queries to methods, as well as finder methods, whose HQL can be inferred from the method signature.
Hibernate 6.3 Examples
This will use Java compiler plugins (aka APT) to generate a
BookRepository_
class with the implementation of the methods, as well as type-check the query and verify that all parameters exist and are of the right type at compile-time.Here is an example of the generate code (when placed in the entity, so mixed with the entity metamodel):
As you can see, this needs an
EntityManager
, which is not convenient, but also defines type-safe references to the attributes asString
orSingularAttribute
objects.Current Hibernate ORM with Panache examples
The previous queries can currently be written as in Hibernate ORM with Panache as:
This isn't necessarily more verbose, but it is not type-safe, and it's really hard to check the HQL at build-time (though we've had some success in the past).
Proposal
We would like to add support for the new type-safe queries to Panache entities and repositories, in addition to the current API, as follows:
As usual, we have to use the
native
trick to allow non-abstract classes to have generated method bodies. These methods will bestatic native
for entities, andnative
for repositories.These generated methods will be type-safe, and their implementation will forward to the generates
Book_
andBookRepository_
classes.Challenges
There are quite a number of challenges and questions to solve in order to support this, including:
annotationProcessorPaths
andannotationProcessors
, as well as generate the sources in thetarget/generated-sources/annotations
folder (previouslytarget/classes
).CodeGen
but IDEs will not be able to understand that they have to run APT, which does not matter for IJ, but does for Eclipse. I need to ask our Tools people.Order
/Page
classesPanacheQuery
,TypedQuery
,SelectionQuery
StatelessSession
, for which we've no real support in PanacheImplementation ideas
No response
The text was updated successfully, but these errors were encountered: