Search in sources :

Example 11 with ParsingException

use of org.hibernate.query.sqm.ParsingException in project hibernate-orm by hibernate.

the class StandardHqlTranslator method parseHql.

private HqlParser.StatementContext parseHql(String hql) {
    // Build the lexer
    final HqlLexer hqlLexer = HqlParseTreeBuilder.INSTANCE.buildHqlLexer(hql);
    // Build the parse tree
    final HqlParser hqlParser = HqlParseTreeBuilder.INSTANCE.buildHqlParser(hql, hqlLexer);
    // try to use SLL(k)-based parsing first - its faster
    hqlLexer.addErrorListener(ERR_LISTENER);
    hqlParser.getInterpreter().setPredictionMode(PredictionMode.SLL);
    hqlParser.removeErrorListeners();
    hqlParser.addErrorListener(ERR_LISTENER);
    hqlParser.setErrorHandler(new BailErrorStrategy());
    try {
        return hqlParser.statement();
    } catch (ParseCancellationException e) {
        // reset the input token stream and parser state
        hqlLexer.reset();
        hqlParser.reset();
        // fall back to LL(k)-based parsing
        hqlParser.getInterpreter().setPredictionMode(PredictionMode.LL);
        hqlParser.setErrorHandler(new DefaultErrorStrategy());
        return hqlParser.statement();
    } catch (ParsingException ex) {
        throw new SemanticException("A query exception occurred", hql, ex);
    }
}
Also used : ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) BailErrorStrategy(org.antlr.v4.runtime.BailErrorStrategy) DefaultErrorStrategy(org.antlr.v4.runtime.DefaultErrorStrategy) HqlLexer(org.hibernate.grammars.hql.HqlLexer) HqlParser(org.hibernate.grammars.hql.HqlParser) ParsingException(org.hibernate.query.sqm.ParsingException) SemanticException(org.hibernate.query.SemanticException)

Aggregations

ParsingException (org.hibernate.query.sqm.ParsingException)11 HqlParser (org.hibernate.grammars.hql.HqlParser)6 ParseTree (org.antlr.v4.runtime.tree.ParseTree)4 SemanticException (org.hibernate.query.SemanticException)4 ArrayList (java.util.ArrayList)3 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)3 StrictJpaComplianceViolation (org.hibernate.query.sqm.StrictJpaComplianceViolation)3 SqmExpression (org.hibernate.query.sqm.tree.expression.SqmExpression)3 BigInteger (java.math.BigInteger)2 PluralPersistentAttribute (org.hibernate.metamodel.model.domain.PluralPersistentAttribute)2 PathException (org.hibernate.query.PathException)2 SqmLiteral (org.hibernate.query.sqm.tree.expression.SqmLiteral)2 EntityExistsException (jakarta.persistence.EntityExistsException)1 EntityNotFoundException (jakarta.persistence.EntityNotFoundException)1 LockTimeoutException (jakarta.persistence.LockTimeoutException)1 NoResultException (jakarta.persistence.NoResultException)1 NonUniqueResultException (jakarta.persistence.NonUniqueResultException)1 OptimisticLockException (jakarta.persistence.OptimisticLockException)1 PersistenceException (jakarta.persistence.PersistenceException)1 PessimisticLockException (jakarta.persistence.PessimisticLockException)1