2019-11-24 13:11:11 -05:00
|
|
|
= SQM
|
2019-10-18 13:46:22 -04:00
|
|
|
|
|
|
|
The Semantic Query Model (SQM) is Hibernate's representation of an HQL or Criteria query's semantic (meaning). This
|
|
|
|
representation is modeled as an "abstract syntax tree" (AST) - meaning it is a structured tree of nodes where each node
|
|
|
|
represrents an atomic piece of the query. E.g. `SqmSelectClause` represents the query's select clause as you might
|
|
|
|
imagine. That `SqmSelectClause` is ultimately a collection of one or more `SqmSelection` references representing the
|
|
|
|
individual selections to be returned from the query (called the domain results).
|
|
|
|
|
2019-11-24 13:11:11 -05:00
|
|
|
== The Tree
|
2019-10-18 13:46:22 -04:00
|
|
|
|
2019-11-24 13:11:11 -05:00
|
|
|
SQM is an Abstract Syntax Tree (AST) describing a query from the perspective of the domain model. It uses the Hibernate
|
|
|
|
domain model, which is Hibernate's extension to the JPA model. This model contains no relational mapping information -
|
|
|
|
it simply describes the domain model in mostly Java terms although it does incorporate "classifications" of the type
|
|
|
|
system. E.g. it understand that `Customer` is an entity, but contains no information about the tables, columns, etc.
|
2019-10-18 13:46:22 -04:00
|
|
|
|
|
|
|
See the `design/type-system-domain.adoc` design doc. For details about this domain model
|
|
|
|
|
2019-11-24 13:11:11 -05:00
|
|
|
The tree model is defined in the package `org.hibernate.query.sqm.tree`
|
2019-10-18 13:46:22 -04:00
|
|
|
|
|
|
|
|
2019-11-24 13:11:11 -05:00
|
|
|
== Building an SQM
|
2019-10-18 13:46:22 -04:00
|
|
|
|
|
|
|
|
2019-11-24 13:11:11 -05:00
|
|
|
=== HQL
|
2019-10-18 13:46:22 -04:00
|
|
|
|
2019-11-24 13:11:11 -05:00
|
|
|
|
|
|
|
=== Criteria
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
== Translating an SQM
|
|
|
|
|
|
|
|
Generic support for walking over the SQM tree via the `org.hibernate.query.sqm.SemanticQueryWalker` contract.
|
|
|
|
|
|
|
|
More specialized support specifically for translating the SQM into a SQL AST is also defined by
|
|
|
|
`org.hibernate.query.sqm.sql.SqmToSqlAstConverter`. The document `design/sql-ast.adoc` for details about the SQL AST,
|
|
|
|
including its execution.
|