Logo

NHibernate

The object-relational mapper for .NET

NHibernate 2.0

This page is converted from the old nhforge.org Wiki. First published by: Diego Jancic on 01-07-2009, Last revision by: Diego Jancic on 01-07-2009

Query Syntax

Below is the HQL full sintax, based on the latest Hibernate version, and which is being implemented in NHibernate. However, some statements or expressions might be not yet valid for NHibernate.

Syntax


<Query> ::= <SelectStatement>
  | <DeleteStatement>
  | <UpdateStatement>
  | <InsertStatement>


<DeleteStatement> ::= DELETE <AliasedEntityName> <WhereClause>
  | DELETE FROM <AliasedEntityName> <WhereClause>


<UpdateStatement> ::= UPDATE <AliasedEntityName> SET <AssignList> <WhereClause>
  | UPDATE VERSIONED <AliasedEntityName> SET <AssignList> <WhereClause>
  | UPDATE FROM <AliasedEntityName> SET <AssignList> <WhereClause>
  | UPDATE VERSIONED FROM <AliasedEntityName> SET <AssignList> <WhereClause>


<AssignList> ::= <EntityName> '=' <Expression> ',' <AssignList>
  | <EntityName> '=' <Expression>


<InsertStatement> ::= INSERT INTO <EntityName> '(' <EntityNameList> ')' <SelectStatement>


<SelectStatement> ::= <SelectClause> <FromClause>
  | <FromClause>


<SelectClause> ::= SELECT <Restriction> <AliasedExpressionList>
  | SELECT NEW <EntityName> '(' <ExpressionList> ')'


<FromClause> ::= FROM <AliasedEntityNameList> <JoinClauseChain> <WhereClause> <GroupByClause> <HavingClause> <OrderByClause>


<JoinClauseChain> ::= <JoinClause> <JoinClauseChain>
  | <JoinClause> ',' <AliasedEntityNameList> <JoinClauseChain>
  |  


<JoinClause> ::= <JoinDefinition> <WithClause>


<JoinDefinition> ::= LEFT JOIN <AliasedEntityName>
  | RIGHT JOIN <AliasedEntityName>
  | LEFT OUTER JOIN <AliasedEntityName>
  | RIGHT OUTER JOIN <AliasedEntityName>
  | FULL JOIN <AliasedEntityName>
  | INNER JOIN <AliasedEntityName>
  | LEFT JOIN FETCH <AliasedEntityName>
  | LEFT OUTER JOIN FETCH <AliasedEntityName>
  | INNER JOIN FETCH <AliasedEntityName>
  | JOIN <AliasedEntityName>
  | JOIN FETCH <AliasedEntityName>


<WithClause> ::= WITH <Expression>
  |  


<WhereClause> ::= WHERE <Expression>
  |  


<GroupByClause> ::= 'GROUP BY' <ExpressionList>
  |  


<HavingClause> ::= HAVING <Expression>
  |  


<OrderByClause> ::= 'ORDER BY' <OrderList>
  |  


<OrderList> ::= <OrderItem> ',' <OrderList>
  | <OrderItem>


<OrderItem> ::= <Expression> <OrderType>


<OrderType> ::= ASC
  | DESC
  | ASCENDING
  | DESCENDING
  |  


<Restriction> ::= ALL
  | DISTINCT
  |  


<AggregateExpression> ::= COUNT '(' '*' ')'
  | COUNT '(' <Restriction> <EntityName> ')'
  | COUNT '(' <Restriction> <CollectionExpression> ')'
  | AVG '(' <MathAddExpression> ')'
  | MIN '(' <MathAddExpression> ')'
  | MAX '(' <MathAddExpression> ')'


<FunctionExpression> ::= Identifier '(' ')'
  | Identifier '(' <ExpressionList> ')'
  | CAST '(' <Expression> AS Identifier ')'
  | <TrimFunctionExpression>
  | <ExtractFunctionExpression>
  | YEAR '(' <Expression> ')'
  | MONTH '(' <Expression> ')'
  | DAY '(' <Expression> ')'
  | HOUR '(' <Expression> ')'
  | MINUTE '(' <Expression> ')'
  | SECOND '(' <Expression> ')'


<TrimFunctionExpression> ::= TRIM '(' <StringValueExpression> ')'
  | TRIM '(' <TrimOperands> <StringValueExpression> ')'


<TrimOperands> ::= <StringValueExpression> FROM
  | <TrimSpecification> <StringValueExpression> FROM
  | <TrimSpecification> FROM
  | FROM


<TrimSpecification> ::= LEADING
  | TRAILING
  | BOTH


<ExtractFunctionExpression> ::= EXTRACT '(' <ExtractField> FROM <Expression> ')'


<ExtractField> ::= YEAR
  | MONTH
  | DAY
  | HOUR
  | MINUTE
  | SECOND
  | 'TIMEZONE_HOUR'
  | 'TIMEZONE_MINUTE'


<CollectionExpression> ::= <ElementsExpression>
  | INDICES '(' Path ')'


<ElementsExpression> ::= ELEMENTS '(' Path ')'


<EntityName> ::= Identifier
  | Path


<EntityNameList> ::= <EntityName> ',' <EntityNameList>
  | <EntityName>


<AliasedEntityName> ::= <EntityName> Identifier
  | <EntityName> AS Identifier
  | Identifier IN CLASS <EntityName>
  | Identifier IN <ElementsExpression>
  | <EntityName>


<AliasedEntityNameList> ::= <AliasedEntityName> ',' <AliasedEntityNameList>
  | <AliasedEntityName>


<AliasedExpression> ::= <Expression> AS Identifier
  | <Expression>


<AliasedExpressionList> ::= <AliasedExpression> ',' <AliasedExpressionList>
  | <AliasedExpression>


<Expression> ::= <OrExpression>
  | <AndExpression>


<OrExpression> ::= <AndExpression> OR <Expression>


<AndExpression> ::= <NotExpression> AND <AndExpression>
  | <NotExpression>


<NotExpression> ::= NOT <PredicateExpression>
  | <PredicateExpression>


<QuantifiedExpression> ::= SOME Path
  | ALL Path
  | ANY Path
  | SOME <CollectionExpression>
  | ALL <CollectionExpression>
  | ANY <CollectionExpression>
  | SOME '(' <SelectStatement> ')'
  | ALL '(' <SelectStatement> ')'
  | ANY '(' <SelectStatement> ')'


<PredicateExpression> ::= <MathAddExpression> BETWEEN <MathAddExpression> AND <MathAddExpression>
  | <MathAddExpression> NOT BETWEEN <MathAddExpression> AND <MathAddExpression>
  | <Value> IS NOT NULL
  | <Value> IS NULL
  | <Value> IS EMPTY
  | <Value> IS NOT EMPTY
  | <MathAddExpression> LIKE <ConcatenationExpression> <LikeEscape>
  | <MathAddExpression> NOT LIKE <ConcatenationExpression> <LikeEscape>
  | <MathAddExpression> IN <Tuple>
  | <MathAddExpression> NOT IN <Tuple>
  | <MathAddExpression> IN <CollectionExpression>
  | <MathAddExpression> NOT IN <CollectionExpression>
  | <MemberPredicate>
  | <ExistsPredicate>
  | <MathAddExpression> '>' <MathAddExpression>
  | <MathAddExpression> '<' <MathAddExpression>
  | <MathAddExpression> '=' <MathAddExpression>
  | <MathAddExpression> '>=' <MathAddExpression>
  | <MathAddExpression> '<=' <MathAddExpression>
  | <MathAddExpression> NotEqualOperator <MathAddExpression>
  | <MathAddExpression> '>' <QuantifiedExpression>
  | <MathAddExpression> '<' <QuantifiedExpression>
  | <MathAddExpression> '=' <QuantifiedExpression>
  | <MathAddExpression> '>=' <QuantifiedExpression>
  | <MathAddExpression> '<=' <QuantifiedExpression>
  | <MathAddExpression> NotEqualOperator <QuantifiedExpression>
  | <MathAddExpression>


<LikeEscape> ::= ESCAPE StringLiteral
  |  


<ExistsPredicate> ::= EXISTS Path
  | EXISTS <CollectionExpression>
  | EXISTS '(' <SelectStatement> ')'


<MemberPredicate> ::= Path MEMBER OF Path
  | Path MEMBER Path


<MathAddExpression> ::= <MathAddExpression> '+' <MathMultExpression>
  | <MathAddExpression> '-' <MathMultExpression>
  | <MathMultExpression>


<MathMultExpression> ::= <MathMultExpression> '*' <MathNegateExpression>
  | <MathMultExpression> '/' <MathNegateExpression>
  | <MathNegateExpression>


<MathNegateExpression> ::= '-' <Value>
  | <Value>


<CaseExpression> ::= <SimpleCaseExpression>
  | <SearchedCaseExpression>


<SimpleCaseExpression> ::= CASE <Value> <SimpleWhenClause> <ElseClause> END


<SearchedCaseExpression> ::= CASE <SearchedWhenClause> <ElseClause> END


<SimpleWhenClause> ::= WHEN <Value> THEN <CaseResult>
  | WHEN <Value> THEN <CaseResult> <SimpleWhenClause>


<SearchedWhenClause> ::= WHEN <Expression> THEN <CaseResult>
  | WHEN <Expression> THEN <CaseResult> <SearchedWhenClause>


<CaseResult> ::= <MathAddExpression>


<ElseClause> ::= ELSE <CaseResult>
  |  


<IndexedExpression> ::= Path '[' <Expression> ']' '.' Path
  | Path '[' <Expression> ']' '.' Identifier
  | Path '[' <Expression> ']'


<StringValueExpression> ::= Identifier
  | Path
  | StringLiteral
  | Parameter
  | <IndexedExpression>
  | <FunctionExpression>
  | <CaseExpression>


<ConcatenationExpression> ::= <StringValueExpression> '||' <ConcatenationExpression>
  | <StringValueExpression>


<Value> ::= <ConcatenationExpression>
  | IntegerLiteral
  | FloatLiteral
  | HexLiteral
  | NULL
  | BooleanLiteral
  | <Tuple>
  | <AggregateExpression>
  | <CollectionExpression>


<Tuple> ::= '(' <SelectStatement> ')'
  | '(' <ExpressionList> ')'


<ExpressionList> ::= <Expression> ',' <ExpressionList>
  | <Expression>

 

© NHibernate Community 2024