Package org.hibernate.query.sqm

This package defines a semantic model of HQL queries.

Semantic Query Model (SQM)

An SQM is a tree representing the semantic interpretation of a query. It's "semantic" in the sense that it contains more information than a simple syntax tree.


HQL is interpreted as an SQM with the help of an ANTRL-generated parser. The class SemanticQueryBuilder is responsible for visiting the syntax tree produced by the parser and building an SQM.

Criteria queries

The SQM tree nodes directly implement the JPA criteria query contracts. For example, SqmFrom implements From.

Our implementation of the JPA CriteriaBuilder interface is SqmCriteriaNodeBuilder. It instantiates SQM nodes and arranges them into SQM tree using the standard operations for building a JPA criteria query.

Transforming SQM to SQL

The package org.hibernate.sql.ast defines an AST representing SQL. To generate SQL from SQM, we must transform the SQM tree to a SQL AST tree. This process is described here, and is handled by a StandardSqmTranslator and a SqlAstTranslator.