Package org.hibernate

Examples of org.hibernate.QueryException


  public QueryableCollection getCollectionPersister(String role) {
    try {
      return ( QueryableCollection ) sfi.getCollectionPersister( role );
    }
    catch ( ClassCastException cce ) {
      throw new QueryException( "collection is not queryable: " + role );
    }
    catch ( Exception e ) {
      throw new QueryException( "collection not found: " + role );
    }
  }
View Full Code Here


        collectionPropertyMappingByRole.put( role, new CollectionPropertyMapping( queryableCollection ) );
      }
      return queryableCollection;
    }
    catch ( ClassCastException cce ) {
      throw new QueryException( "collection role is not queryable: " + role );
    }
    catch ( Exception e ) {
      throw new QueryException( "collection role not found: " + role );
    }
  }
View Full Code Here

  public String getIdentifierOrUniqueKeyPropertyName(EntityType entityType) {
    try {
      return entityType.getIdentifierOrUniqueKeyPropertyName( sfi );
    }
    catch ( MappingException me ) {
      throw new QueryException( me );
    }
  }
View Full Code Here

   * @throws QueryException Indicates no matching sql functions could be found.
   */
  private SQLFunction requireSQLFunction(String functionName) {
    SQLFunction f = findSQLFunction( functionName );
    if ( f == null ) {
      throw new QueryException( "Unable to find SQL function: " + functionName );
    }
    return f;
  }
View Full Code Here

  }

  public SQLQuery addJoin(String alias, String path, LockMode lockMode) {
    int loc = path.indexOf('.');
    if ( loc < 0 ) {
      throw new QueryException( "not a property path: " + path );
    }
    String ownerAlias = path.substring(0, loc);
    String role = path.substring(loc+1);
    queryReturns.add( new NativeSQLQueryJoinReturn(alias, ownerAlias, role, CollectionHelper.EMPTY_MAP, lockMode) );
    return this;
View Full Code Here

      throw new SemanticException( "The [] operator cannot be applied to type " + type.toString() );
    }
    String collectionRole = ( ( CollectionType ) type ).getRole();
    QueryableCollection queryableCollection = sessionFactoryHelper.requireQueryableCollection( collectionRole );
    if ( !queryableCollection.hasIndex() ) {
      throw new QueryException( "unindexed fromElement before []: " + collectionNode.getPath() );
    }

    // Generate the inner join -- The elements need to be joined to the collection they are in.
    FromElement fromElement = collectionNode.getFromElement();
    String elementTable = fromElement.getTableAlias();
    FromClause fromClause = fromElement.getFromClause();
    String path = collectionNode.getPath();

    FromElement elem = fromClause.findCollectionJoin( path );
    if ( elem == null ) {
      FromElementFactory factory = new FromElementFactory( fromClause, fromElement, path );
      elem = factory.createCollectionElementsJoin( queryableCollection, elementTable );
      if ( log.isDebugEnabled() ) {
        log.debug( "No FROM element found for the elements of collection join path " + path
            + ", created " + elem );
      }
    }
    else {
      if ( log.isDebugEnabled() ) {
        log.debug( "FROM element found for collection join path " + path );
      }
    }

    // Add the condition to the join sequence that qualifies the indexed element.
    AST index = collectionNode.getNextSibling()// The index should be a constant, which will have been processed already.
    if ( index == null ) {
      throw new QueryException( "No index value!" );
    }

    setFromElement( fromElement );              // The 'from element' that represents the elements of the collection.

    // Sometimes use the element table alias, sometimes use the... umm... collection table alias (many to many)
    String collectionTableAlias = elementTable;
    if ( elem.getCollectionTableAlias() != null ) {
      collectionTableAlias = elem.getCollectionTableAlias();
    }

    // TODO: get SQL rendering out of here, create an AST for the join expressions.
    // Use the SQL generator grammar to generate the SQL text for the index expression.
    JoinSequence joinSequence = fromElement.getJoinSequence();
    String[] indexCols = queryableCollection.getIndexColumnNames();
    if ( indexCols.length != 1 ) {
      throw new QueryException( "composite-index appears in []: " + collectionNode.getPath() );
    }
    SqlGenerator gen = new SqlGenerator( getSessionFactoryHelper().getFactory() );
    try {
      gen.simpleExpr( index ); //TODO: used to be exprNoParens! was this needed?
    }
    catch ( RecognitionException e ) {
      throw new QueryException( e.getMessage(), e );
    }
    String expression = gen.getSQL();
    joinSequence.addCondition( collectionTableAlias + '.' + indexCols[0] + " = " + expression );

    // Now, set the text for this node.  It should be the element columns.
View Full Code Here

      throw me;
    }
    catch ( Exception e ) {
      log.debug( "unexpected query compilation problem", e );
      e.printStackTrace();
      QueryException qe = new QueryException( "Incorrect query syntax", e );
      qe.setQueryString( queryString );
      throw qe;
    }

    postInstantiate();
View Full Code Here

    String type = getType( name );
    if ( type == null ) {
      String role = getRole( name );
      if ( role == null ) {
        throw new QueryException( "alias not found: " + name );
      }
      return getCollectionPersister( role ); //.getElementPropertyMapping();
    }
    else {
      Queryable persister = getEntityPersister( type );
      if ( persister == null ) throw new QueryException( "persistent class not found: " + type );
      return persister;
    }
  }
View Full Code Here

  }

  private Queryable getEntityPersisterForName(String name) throws QueryException {
    String type = getType( name );
    Queryable persister = getEntityPersister( type );
    if ( persister == null ) throw new QueryException( "persistent class not found: " + type );
    return persister;
  }
View Full Code Here

  Queryable getEntityPersister(String entityName) throws QueryException {
    try {
      return ( Queryable ) getFactory().getEntityPersister( entityName );
    }
    catch ( Exception e ) {
      throw new QueryException( "persistent class not found: " + entityName );
    }
  }
View Full Code Here

TOP

Related Classes of org.hibernate.QueryException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.