Hi Jonleyo
This is a so good question! :)
I found this problem and I decide to resolve it in my framework several years ago, but I finally give up it because time is not enough.
The current solution:
Code:
JPA Criteria -> JPQL Source Code -> HQL AST(by antlr parser) -> SQL AST(by antlr walker) -> Generated SQL
The better solution:
Code:
JPA Criteria(Enahanced HQL AST)--\
+-> SQL AST(by antlr walker) -> Gnerated SQL
JPQLSource Code-> HQL AST--------/
Let the JPA Criteria to be the enahced HQL AST directly(Criteria class implements the same internal interface of AST), then the JPA Criteria need not to use the QueryPlanCache and HQL Compiler.
I hope this functionality will be implemented by Hibernate in the future, I believe it can become stronger and stronger in the future.