Search in sources :

Example 1 with InterpretationException

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

the class StandardHqlTranslator method translate.

@Override
public <R> SqmStatement<R> translate(String query) {
    HqlLogging.QUERY_LOGGER.debugf("HQL : " + query);
    final HqlParser.StatementContext hqlParseTree = parseHql(query);
    // then we perform semantic analysis and build the semantic representation...
    try {
        final SqmStatement<R> sqmStatement = SemanticQueryBuilder.buildSemanticModel(hqlParseTree, sqmCreationOptions, sqmCreationContext);
        // Log the SQM tree (if enabled)
        SqmTreePrinter.logTree(sqmStatement);
        return sqmStatement;
    } catch (QueryException e) {
        throw e;
    } catch (Exception e) {
        throw new InterpretationException(query, e);
    }
}
Also used : QueryException(org.hibernate.QueryException) InterpretationException(org.hibernate.query.sqm.InterpretationException) HqlParser(org.hibernate.grammars.hql.HqlParser) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) InterpretationException(org.hibernate.query.sqm.InterpretationException) SemanticException(org.hibernate.query.SemanticException) RecognitionException(org.antlr.v4.runtime.RecognitionException) ParsingException(org.hibernate.query.sqm.ParsingException) QueryException(org.hibernate.QueryException)

Example 2 with InterpretationException

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

the class BaseSqmToSqlAstConverter method visitTreatedPath.

@Override
public Expression visitTreatedPath(SqmTreatedPath<?, ?> sqmTreatedPath) {
    prepareReusablePath(sqmTreatedPath, () -> null);
    final TableGroup resolved = getFromClauseAccess().findTableGroup(sqmTreatedPath.getNavigablePath());
    if (resolved != null) {
        log.tracef("SqmTreatedPath [%s] resolved to existing TableGroup [%s]", sqmTreatedPath, resolved);
        return visitTableGroup(resolved, (SqmFrom<?, ?>) sqmTreatedPath);
    }
    throw new InterpretationException("SqmTreatedPath not yet resolved to TableGroup");
}
Also used : VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) InterpretationException(org.hibernate.query.sqm.InterpretationException)

Example 3 with InterpretationException

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

the class ExceptionConverterImpl method convert.

@Override
public RuntimeException convert(HibernateException exception, LockOptions lockOptions) {
    if (exception instanceof StaleStateException) {
        final PersistenceException converted = wrapStaleStateException((StaleStateException) exception);
        handlePersistenceException(converted);
        return converted;
    } else if (exception instanceof LockAcquisitionException) {
        final PersistenceException converted = wrapLockException(exception, lockOptions);
        handlePersistenceException(converted);
        return converted;
    } else if (exception instanceof LockingStrategyException) {
        final PersistenceException converted = wrapLockException(exception, lockOptions);
        handlePersistenceException(converted);
        return converted;
    } else if (exception instanceof org.hibernate.PessimisticLockException) {
        final PersistenceException converted = wrapLockException(exception, lockOptions);
        handlePersistenceException(converted);
        return converted;
    } else if (exception instanceof org.hibernate.QueryTimeoutException) {
        final QueryTimeoutException converted = new QueryTimeoutException(exception.getMessage(), exception);
        handlePersistenceException(converted);
        return converted;
    } else if (exception instanceof ObjectNotFoundException) {
        final EntityNotFoundException converted = new EntityNotFoundException(exception.getMessage());
        handlePersistenceException(converted);
        return converted;
    } else if (exception instanceof org.hibernate.NonUniqueObjectException) {
        final EntityExistsException converted = new EntityExistsException(exception.getMessage());
        handlePersistenceException(converted);
        return converted;
    } else if (exception instanceof org.hibernate.NonUniqueResultException) {
        final NonUniqueResultException converted = new NonUniqueResultException(exception.getMessage());
        handlePersistenceException(converted);
        return converted;
    } else if (exception instanceof UnresolvableObjectException) {
        final EntityNotFoundException converted = new EntityNotFoundException(exception.getMessage());
        handlePersistenceException(converted);
        return converted;
    } else if (exception instanceof SemanticException) {
        return new IllegalArgumentException(exception);
    } else if (exception instanceof QueryException) {
        return new IllegalArgumentException(exception);
    } else if (exception instanceof InterpretationException) {
        return new IllegalArgumentException(exception);
    } else if (exception instanceof ParsingException) {
        return new IllegalArgumentException(exception);
    } else if (exception instanceof MultipleBagFetchException) {
        return new IllegalArgumentException(exception);
    } else if (exception instanceof TransientObjectException) {
        try {
            sharedSessionContract.markForRollbackOnly();
        } catch (Exception ne) {
            // we do not want the subsequent exception to swallow the original one
            log.unableToMarkForRollbackOnTransientObjectException(ne);
        }
        // Spec 3.2.3 Synchronization rules
        return new IllegalStateException(exception);
    } else {
        final PersistenceException converted = new PersistenceException("Converting `" + exception.getClass().getName() + "` to JPA `PersistenceException` : " + exception.getMessage(), exception);
        handlePersistenceException(converted);
        return converted;
    }
}
Also used : NonUniqueResultException(jakarta.persistence.NonUniqueResultException) TransientObjectException(org.hibernate.TransientObjectException) LockingStrategyException(org.hibernate.dialect.lock.LockingStrategyException) EntityNotFoundException(jakarta.persistence.EntityNotFoundException) EntityExistsException(jakarta.persistence.EntityExistsException) LockAcquisitionException(org.hibernate.exception.LockAcquisitionException) MultipleBagFetchException(org.hibernate.loader.MultipleBagFetchException) PessimisticLockException(jakarta.persistence.PessimisticLockException) InterpretationException(org.hibernate.query.sqm.InterpretationException) PersistenceException(jakarta.persistence.PersistenceException) SemanticException(org.hibernate.query.SemanticException) UnresolvableObjectException(org.hibernate.UnresolvableObjectException) SQLException(java.sql.SQLException) JDBCException(org.hibernate.JDBCException) EntityExistsException(jakarta.persistence.EntityExistsException) QueryTimeoutException(jakarta.persistence.QueryTimeoutException) EntityNotFoundException(jakarta.persistence.EntityNotFoundException) StaleStateException(org.hibernate.StaleStateException) OptimisticEntityLockException(org.hibernate.dialect.lock.OptimisticEntityLockException) LockingStrategyException(org.hibernate.dialect.lock.LockingStrategyException) StaleObjectStateException(org.hibernate.StaleObjectStateException) RollbackException(jakarta.persistence.RollbackException) PessimisticEntityLockException(org.hibernate.dialect.lock.PessimisticEntityLockException) TransientObjectException(org.hibernate.TransientObjectException) LockTimeoutException(jakarta.persistence.LockTimeoutException) NonUniqueResultException(jakarta.persistence.NonUniqueResultException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) ParsingException(org.hibernate.query.sqm.ParsingException) HibernateException(org.hibernate.HibernateException) NoResultException(jakarta.persistence.NoResultException) OptimisticLockException(jakarta.persistence.OptimisticLockException) QueryException(org.hibernate.QueryException) QueryTimeoutException(jakarta.persistence.QueryTimeoutException) QueryException(org.hibernate.QueryException) StaleStateException(org.hibernate.StaleStateException) InterpretationException(org.hibernate.query.sqm.InterpretationException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) ParsingException(org.hibernate.query.sqm.ParsingException) PersistenceException(jakarta.persistence.PersistenceException) UnresolvableObjectException(org.hibernate.UnresolvableObjectException) MultipleBagFetchException(org.hibernate.loader.MultipleBagFetchException) LockAcquisitionException(org.hibernate.exception.LockAcquisitionException) SemanticException(org.hibernate.query.SemanticException)

Aggregations

InterpretationException (org.hibernate.query.sqm.InterpretationException)3 QueryException (org.hibernate.QueryException)2 SemanticException (org.hibernate.query.SemanticException)2 ParsingException (org.hibernate.query.sqm.ParsingException)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 QueryTimeoutException (jakarta.persistence.QueryTimeoutException)1 RollbackException (jakarta.persistence.RollbackException)1 SQLException (java.sql.SQLException)1 RecognitionException (org.antlr.v4.runtime.RecognitionException)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1 HibernateException (org.hibernate.HibernateException)1 JDBCException (org.hibernate.JDBCException)1 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)1