Search in sources :

Example 16 with SemanticException

use of antlr.SemanticException in project hibernate-orm by hibernate.

the class HqlSqlWalker method createFromJoinElement.

@Override
protected void createFromJoinElement(AST path, AST alias, int joinType, AST fetchNode, AST propertyFetch, AST with) throws SemanticException {
    boolean fetch = fetchNode != null;
    if (fetch && isSubQuery()) {
        throw new QueryException("fetch not allowed in subquery from-elements");
    }
    // the incoming "path" can be either:
    //		1) an implicit join path (join p.address.city)
    // 		2) an entity-join (join com.acme.User)
    //
    // so make the proper interpretation here...
    final EntityPersister entityJoinReferencedPersister = resolveEntityJoinReferencedPersister(path);
    if (entityJoinReferencedPersister != null) {
        // `path` referenced an entity
        final EntityJoinFromElement join = createEntityJoin(entityJoinReferencedPersister, alias, joinType, propertyFetch, with);
        ((FromReferenceNode) path).setFromElement(join);
    } else {
        if (path.getType() != SqlTokenTypes.DOT) {
            throw new SemanticException("Path expected for join!");
        }
        DotNode dot = (DotNode) path;
        JoinType hibernateJoinType = JoinProcessor.toHibernateJoinType(joinType);
        // Tell the dot node about the join type.
        dot.setJoinType(hibernateJoinType);
        dot.setFetch(fetch);
        // Generate an explicit join for the root dot node.   The implied joins will be collected and passed up
        // to the root dot node.
        dot.resolve(true, false, alias == null ? null : alias.getText());
        final FromElement fromElement;
        if (dot.getDataType() != null && dot.getDataType().isComponentType()) {
            if (dot.getDataType().isAnyType()) {
                throw new SemanticException("An AnyType attribute cannot be join fetched");
            // ^^ because the discriminator (aka, the "meta columns") must be known to the SQL in
            // 		a non-parameterized way.
            }
            FromElementFactory factory = new FromElementFactory(getCurrentFromClause(), dot.getLhs().getFromElement(), dot.getPropertyPath(), alias == null ? null : alias.getText(), null, false);
            fromElement = factory.createComponentJoin((CompositeType) dot.getDataType());
        } else {
            fromElement = dot.getImpliedJoin();
            fromElement.setAllPropertyFetch(propertyFetch != null);
            if (with != null) {
                if (fetch) {
                    throw new SemanticException("with-clause not allowed on fetched associations; use filters");
                }
                handleWithFragment(fromElement, with);
            }
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("createFromJoinElement() : " + getASTPrinter().showAsString(fromElement, "-- join tree --"));
        }
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) FromReferenceNode(org.hibernate.hql.internal.ast.tree.FromReferenceNode) QueryException(org.hibernate.QueryException) EntityJoinFromElement(org.hibernate.hql.internal.ast.tree.EntityJoinFromElement) DotNode(org.hibernate.hql.internal.ast.tree.DotNode) FromElement(org.hibernate.hql.internal.ast.tree.FromElement) EntityJoinFromElement(org.hibernate.hql.internal.ast.tree.EntityJoinFromElement) JoinType(org.hibernate.sql.JoinType) FromElementFactory(org.hibernate.hql.internal.ast.tree.FromElementFactory) SemanticException(antlr.SemanticException) CompositeType(org.hibernate.type.CompositeType)

Example 17 with SemanticException

use of antlr.SemanticException in project hibernate-orm by hibernate.

the class FromElementFactory method createCollectionJoin.

private FromElement createCollectionJoin(JoinSequence collectionJoinSequence, String tableAlias) throws SemanticException {
    String text = queryableCollection.getTableName();
    AST ast = createFromElement(text);
    FromElement destination = (FromElement) ast;
    Type elementType = queryableCollection.getElementType();
    if (elementType.isCollectionType()) {
        throw new SemanticException("Collections of collections are not supported!");
    }
    destination.initializeCollection(fromClause, classAlias, tableAlias);
    // Tag this node as a JOIN.
    destination.setType(JOIN_FRAGMENT);
    // Don't include subclasses in the join.
    destination.setIncludeSubclasses(false);
    // This is a clollection join.
    destination.setCollectionJoin(true);
    destination.setJoinSequence(collectionJoinSequence);
    destination.setOrigin(origin, false);
    destination.setCollectionTableAlias(tableAlias);
    //		origin.addDestination( destination );
    // This was the cause of HHH-242
    //		origin.setType( FROM_FRAGMENT );			// Set the parent node type so that the AST is properly formed.
    // The destination node will have all the FROM text.
    origin.setText("");
    // The parent node is a collection join too (voodoo - see JoinProcessor)
    origin.setCollectionJoin(true);
    fromClause.addCollectionJoinFromElementByPath(path, destination);
    fromClause.getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces());
    return destination;
}
Also used : AST(antlr.collections.AST) JoinType(org.hibernate.sql.JoinType) CollectionType(org.hibernate.type.CollectionType) EntityType(org.hibernate.type.EntityType) CompositeType(org.hibernate.type.CompositeType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) SemanticException(antlr.SemanticException)

Aggregations

SemanticException (antlr.SemanticException)17 Type (org.hibernate.type.Type)7 AST (antlr.collections.AST)6 QueryException (org.hibernate.QueryException)4 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)3 JoinType (org.hibernate.sql.JoinType)3 CollectionType (org.hibernate.type.CollectionType)3 RecognitionException (antlr.RecognitionException)2 FromReferenceNode (org.hibernate.hql.internal.ast.tree.FromReferenceNode)2 ParameterNode (org.hibernate.hql.internal.ast.tree.ParameterNode)2 ParameterSpecification (org.hibernate.param.ParameterSpecification)2 PositionalParameterSpecification (org.hibernate.param.PositionalParameterSpecification)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 CompositeType (org.hibernate.type.CompositeType)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PropertyNotFoundException (org.hibernate.PropertyNotFoundException)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1 JoinSequence (org.hibernate.engine.internal.JoinSequence)1