persistence icon indicating copy to clipboard operation
persistence copied to clipboard

Constructing a CriteriaQuery from a Query

Open lukasj opened this issue 13 years ago • 8 comments

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.

lukasj avatar May 24 '12 21:05 lukasj

  • Issue Imported From: https://github.com/javaee/jpa-spec/issues/29
  • Original Issue Raised By:@glassfishrobot
  • Original Issue Assigned To: @ldemichiel

lukasj avatar Aug 31 '18 16:08 lukasj

@glassfishrobot Commented Reported by @arjantijms

lukasj avatar May 24 '12 21:05 lukasj

@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.

lukasj avatar Feb 22 '13 22:02 lukasj

@glassfishrobot Commented This issue was imported from java.net JIRA JPA_SPEC-29

lukasj avatar May 05 '17 06:05 lukasj

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.

beikov avatar Mar 18 '22 12:03 beikov

Thanks @beikov, hope to have some bandwidth for this after EE 10.

arjantijms avatar Mar 18 '22 16:03 arjantijms