Constructing a CriteriaQuery from a Query
In JPA 2 a query can be defined in JPQL for which a Query instance can be constructed, or via a Criteria for which a CriteriaQuery can be build. Via the EntityManager, a Query can be created from a CriteriaQuery.
However, it's not possible to create a CriteriaQuery from a Query. This would be particular useful for those use cases where a base query is written in the arguably more readable JPQL, which can then be transformed to a Criteria such that (small) modifications can be made to it programmatically. Such modifications could e.g. be adding an extra condition in an existing WHERE clause, adding an ORDER BY clause, etc.
I would like to request to add this capability.
- Issue Imported From: https://github.com/javaee/jpa-spec/issues/29
- Original Issue Raised By:@glassfishrobot
- Original Issue Assigned To: @ldemichiel
@glassfishrobot Commented Reported by @arjantijms
@glassfishrobot Commented @ldemichiel said: Being able to map back and forth between CriteriaQueries and JPQL queries would be useful to have. This is something that should be considered in a future release.
@glassfishrobot Commented This issue was imported from java.net JIRA JPA_SPEC-29
FWIW this could be easily implemented in Hibernate 6.0 as HQL translates to an AST that implements the JPA Criteria API. If anyone is willing to work on this, Hibernate can serve as a compatible implementation.
Thanks @beikov, hope to have some bandwidth for this after EE 10.