Package org.hibernate

Examples of org.hibernate.QueryException


  }

  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

  QueryableCollection getCollectionPersister(String role) throws QueryException {
    try {
      return ( QueryableCollection ) getFactory().getCollectionPersister( role );
    }
    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 int[] getNamedParameterLocs(String name) throws QueryException {
    Object o = namedParameters.get( name );
    if ( o == null ) {
      QueryException qe = new QueryException( ERROR_NAMED_PARAMETER_DOES_NOT_APPEAR + name );
      qe.setQueryString( queryString );
      throw qe;
    }
    if ( o instanceof Integer ) {
      return new int[]{ ( ( Integer ) o ).intValue() };
    }
View Full Code Here

      throws QueryException {
    //q.addCollection(collectionName, collectionRole);
    QueryableCollection persister = getCollectionPersister( collectionRole );
    Type collectionElementType = persister.getElementType();
    if ( !collectionElementType.isEntityType() ) {
      throw new QueryException( "collection of values in filter: " + elementName );
    }

    String[] keyColumnNames = persister.getKeyColumnNames();
    //if (keyColumnNames.length!=1) throw new QueryException("composite-key collection in filter: " + collectionRole);

    String collectionName;
    JoinSequence join = new JoinSequence( getFactory() );
    collectionName = persister.isOneToMany() ?
        elementName :
        createNameForCollection( collectionRole );
    join.setRoot( persister, collectionName );
    if ( !persister.isOneToMany() ) {
      //many-to-many
      addCollection( collectionName, collectionRole );
      try {
        join.addJoin( ( AssociationType ) persister.getElementType(),
            elementName,
            JoinFragment.INNER_JOIN,
            persister.getElementColumnNames(collectionName) );
      }
      catch ( MappingException me ) {
        throw new QueryException( me );
      }
    }
    join.addCondition( collectionName, keyColumnNames, " = ?" );
    //if ( persister.hasWhere() ) join.addCondition( persister.getSQLWhereString(collectionName) );
    EntityType elemType = ( EntityType ) collectionElementType;
View Full Code Here

        Object[] row = ( Object[] ) results.get( i );
        try {
          results.set( i, holderConstructor.newInstance( row ) );
        }
        catch ( Exception e ) {
          throw new QueryException( "could not instantiate: " + holderClass, e );
        }
      }
    }
    return results;
  }
View Full Code Here

  public String[] toColumns(String alias, String propertyName)
      throws QueryException {

    if ( "index".equals( propertyName ) ) {
      if ( isManyToMany() ) {
        throw new QueryException( "index() function not supported for many-to-many association" );
      }
      return StringHelper.qualify( alias, indexColumnNames );
    }

    return elementPropertyMapping.toColumns( alias, propertyName );
View Full Code Here

  public String[] toColumns(String propertyName)
      throws QueryException {

    if ( "index".equals( propertyName ) ) {
      if ( isManyToMany() ) {
        throw new QueryException( "index() function not supported for many-to-many association" );
      }
      return indexColumnNames;
    }

    return elementPropertyMapping.toColumns( propertyName );
View Full Code Here

  protected void verifyParameters(boolean reserveFirstParameter) throws HibernateException {
    if ( parameterMetadata.getNamedParameterNames().size() != namedParameters.size() + namedParameterLists.size() ) {
      Set missingParams = new HashSet( parameterMetadata.getNamedParameterNames() );
      missingParams.removeAll( namedParameterLists.keySet() );
      missingParams.removeAll( namedParameters.keySet() );
      throw new QueryException( "Not all named parameters have been set: " + missingParams, getQueryString() );
    }

    int positionalValueSpan = 0;
    for ( int i = 0; i < values.size(); i++ ) {
      Object object = types.get( i );
      if( values.get( i ) == UNSET_PARAMETER || object == UNSET_TYPE ) {
        if ( reserveFirstParameter && i==0 ) {
          continue;
        }
        else {
          throw new QueryException( "Unset positional parameter at position: " + i, getQueryString() );
        }
      }
      positionalValueSpan += ( (Type) object ).getColumnSpan( session.getFactory() );
    }

    if ( parameterMetadata.getOrdinalParameterCount() != positionalValueSpan ) {
      if ( reserveFirstParameter && parameterMetadata.getOrdinalParameterCount() - 1 != positionalValueSpan ) {
        throw new QueryException(
             "Expected positional parameter count: " +
             (parameterMetadata.getOrdinalParameterCount()-1) +
             ", actual parameters: " +
             values,
             getQueryString()
           );
      }
      else if ( !reserveFirstParameter ) {
        throw new QueryException(
             "Expected positional parameter count: " +
             parameterMetadata.getOrdinalParameterCount() +
             ", actual parameters: " +
             values,
             getQueryString()
View Full Code Here

    return StringHelper.replace( query, paramPrefix + name, list.toString(), true );
  }

  public Query setParameterList(String name, Collection vals) throws HibernateException {
    if ( vals == null ) {
      throw new QueryException( "Collection must be not null!" );
    }

    if( vals.size() == 0 ) {
      setParameterList( name, vals, null );
    }
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.