HIBERNATE JBoss.org
 |  Register  | 
     
News 
About 
   Feature List 
   Road Map 
Documentation 
   Related Projects 
   External Documentation 
Download 
Forum & Mailinglists 
Support & Training 
JIRA Issue Tracking
Wiki Community Area


Hibernate Public Training Courses


Get Hibernate in Action eBook!


JavaWorld 2003 Finalist


Jolt Award 2004 Winner
      
Documentation > Community Area > HQL BNF

HQL BNF

Here is a partial BNF for the Hibernate2 Query Language

(this is meant more for the purposes of documentation than as

a grammer for a parser compiler).

query:
    [selectClause] fromClause [whereClause] [groupByClause] 
    [havingClause] [orderByClause];

selectClause:
    SELECT DISTINCT? selectedPropertiesList | 
    ( NEW className OPEN selectedPropertiesList CLOSE );

fromClause:
    FROM className AS? identifier 
    (  ( COMMA className AS? identifier ) | 
       ( joinType path AS? identifier ) )*;

joinType:
    ( ( 'left'|'right' 'outer'? ) | 'full' | 'inner' )? JOIN FETCH?;

groupByClause:
    GROUP_BY path ( COMMA path )*;

orderByClause:
    ORDER_BY selectedPropertiesList;

havingClause:
    HAVING logicalExpression;

whereClause:
    WHERE logicalExpression;

selectedPropertiesList:
    ( path | aggregate ) ( COMMA path | aggregate )*;

aggregate:
    ( aggregateFunction OPEN path CLOSE ) |  
    ( COUNT OPEN STAR CLOSE ) |  ( COUNT OPEN DISTINCT | 
      ALL path CLOSE );

aggregateFunction:
    COUNT | 'sum' | 'avg' | 'max' | 'min';

logicalExpression: TODO!

expression: TODO!

collection: ( OPEN query CLOSE ) | 
     ( 'elements'|'indices' OPEN path CLOSE );

quantifiedExpression: 'exists' | ( expression 'in' ) | 
            ( expression OP 'any' | 'some' ) collection;

compoundPath: path ( OPEN_BRACKET expression CLOSE_BRACKET 
             ( '.' path )? )*;

path: identifier ( '.' identifier )*;

className: path;

OP: EQ | LT | GT | LE | GE | NE | SQL_NE | LIKE;

AS: 'as';
DISTINCT: 'distinct';
ALL: 'all';
COUNT: 'count';
SELECT: 'select';
FROM: 'from';
JOIN: 'join;
FETCH: 'fetch'
BY: 'by';
GROUP_BY: 'group' BY;
ORDER_BY: 'order' BY;
HAVING: 'having';
WHERE: 'where';
NEW: 'new';

LIKE: 'like';
EQ: '=';
LT: '<';
GT: '>';
SQL_NE: "<>";
NE: "!=" | "^=";
LE: "<=";
GE: ">=";

COMMA: ',';

OPEN: '(';
CLOSE: ')';
OPEN_BRACKET: '[';
CLOSE_BRACKET: ']';

CONCAT: "||";
PLUS: '+';
MINUS: '-';
STAR: '*';
DIV: '/';
      

coWiki