[hibernate-dev] SQM : Criteria translation design

Steve Ebersole steve at hibernate.org
Fri Oct 30 07:41:12 EDT 2015


I started work on SQM-24 which covers translation of criteria queries into
SQM.

The difficulty with this is that the JPA contracts alone do not give enough
information to really be able to understand the semantics of the query;
there is just not enough information exposed.  I can get into specific
examples if that helps, but for now lets take that as a given...

So then how do we go about translating a criteria into an SQM?  There are
going to be 2 main approaches.  Each requires some level of extension to
the standard contracts:

The first approach is to use visitation.  The criteria nodes would be
expected to implement an SQM extension accepting a visitor and do the right
thing.  The gains here are the normal gains with the visitor pattern.  The
downside is that this makes SQM highly dependent on the criteria impl doing
the right thing and makes the criteria impl sensitive to SQM (depending n
how we expose the visitation methods to a degree).

The second approach would be to extended the standard criteria contracts to
more fully cover the semantic.  As one example, JPA defines just Predicate
(for the most part) without exposing the type of predicate.  Is it a LIKE
expression?  A BETWEEN?  A Comparison (=, !=, <, etc)?  We just don't know
from the standard contracts.  So we'd have to develop a full semantic
extension model here.  `interface LikePredicate extends Predicate`,
`BetweenPredicate extends Predicate`, etc.

I lean towards the visitor approach given these choices.  Anyone else have
opinions?  Other options?


More information about the hibernate-dev mailing list