Package org.hibernate

Examples of org.hibernate.QueryException


    return joinSequence;
  }

  public String getWhereColumn() throws QueryException {
    if ( columns.length != 1 ) {
      throw new QueryException( "path expression ends in a composite value: " + path );
    }
    return columns[0];
  }
View Full Code Here


  public String addFromCollection(QueryTranslatorImpl q) throws QueryException {
    Type collectionElementType = getPropertyType();

    if ( collectionElementType == null ) {
      throw new QueryException( "must specify 'elements' for collection valued property in from clause: " + path );
    }

    if ( collectionElementType.isEntityType() ) {
      // an association
      QueryableCollection collectionPersister = q.getCollectionPersister( collectionRole );
View Full Code Here

        // Handle collection-fiter compilation.
        // IMPORTANT NOTE: This is modifying the INPUT (HQL) tree, not the output tree!
        QueryableCollection persister = sessionFactoryHelper.getCollectionPersister( collectionFilterRole );
        Type collectionElementType = persister.getElementType();
        if ( !collectionElementType.isEntityType() ) {
          throw new QueryException( "collection of values in filter: this" );
        }

        String collectionElementEntityName = persister.getElementPersister().getEntityName();
        ASTFactory inputAstFactory = hqlParser.getASTFactory();
        AST fromElement = ASTUtil.create( inputAstFactory, HqlTokenTypes.FILTER_ENTITY, collectionElementEntityName );
View Full Code Here

          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 path AST should be a DotNode, and it should have been evaluated already.
    if ( path.getType() != SqlTokenTypes.DOT ) {
      throw new SemanticException( "Path expected for join!" );
    }
View Full Code Here

      //
      // Note that this is only supported for sequence-style generators and
      // post-insert-style generators; basically, only in-db generators
      IdentifierGenerator generator = persister.getIdentifierGenerator();
      if ( !supportsIdGenWithBulkInsertion( generator ) ) {
        throw new QueryException( "can only generate ids as part of bulk insert with either sequence or post-insert style generators" );
      }

      AST idSelectExprNode = null;

      if ( SequenceGenerator.class.isAssignableFrom( generator.getClass() ) ) {
        String seqName = ( String ) ( ( SequenceGenerator ) generator ).generatorKey();
        String nextval = sessionFactoryHelper.getFactory().getDialect().getSelectSequenceNextValString( seqName );
        idSelectExprNode = getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, nextval );
      }
      else {
        //Don't need this, because we should never ever be selecting no columns in an insert ... select...
        //and because it causes a bug on DB2
        /*String idInsertString = sessionFactoryHelper.getFactory().getDialect().getIdentityInsertString();
        if ( idInsertString != null ) {
          idSelectExprNode = getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, idInsertString );
        }*/
      }

      if ( idSelectExprNode != null ) {
        AST currentFirstSelectExprNode = selectClause.getFirstChild();
        selectClause.setFirstChild( idSelectExprNode );
        idSelectExprNode.setNextSibling( currentFirstSelectExprNode );

        insertStatement.getIntoClause().prependIdColumnSpec();
      }
    }

    final boolean includeVersionProperty = persister.isVersioned() &&
        !insertStatement.getIntoClause().isExplicitVersionInsertion() &&
        persister.isVersionPropertyInsertable();
    if ( includeVersionProperty ) {
      // We need to seed the version value as part of this bulk insert
      VersionType versionType = persister.getVersionType();
      AST versionValueNode = null;

      if ( sessionFactoryHelper.getFactory().getDialect().supportsParametersInInsertSelect() ) {
        versionValueNode = getASTFactory().create( HqlSqlTokenTypes.PARAM, "?" );
        ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification( versionType );
        ( ( ParameterNode ) versionValueNode ).setHqlParameterSpecification( paramSpec );
        parameters.add( 0, paramSpec );
      }
      else {
        if ( isIntegral( versionType ) ) {
          try {
            Object seedValue = versionType.seed( null );
            versionValueNode = getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, seedValue.toString() );
          }
          catch( Throwable t ) {
            throw new QueryException( "could not determine seed value for version on bulk insert [" + versionType + "]" );
          }
        }
        else if ( isDatabaseGeneratedTimestamp( versionType ) ) {
          String functionName = sessionFactoryHelper.getFactory().getDialect().getCurrentTimestampSQLFunctionName();
          versionValueNode = getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, functionName );
        }
        else {
          throw new QueryException( "cannot handle version type [" + versionType + "] on bulk inserts with dialects not supporting parameters in insert-select statements" );
        }
      }

      AST currentFirstSelectExprNode = selectClause.getFirstChild();
      selectClause.setFirstChild( versionValueNode );
View Full Code Here

   * Returns the locations of all occurrences of the named parameter.
   */
  public int[] getNamedParameterLocations(String name) throws QueryException {
    Object o = namedParameters.get( name );
    if ( o == null ) {
      QueryException qe = new QueryException( QueryTranslator.ERROR_NAMED_PARAMETER_DOES_NOT_APPEAR + name );
      qe.setQueryString( queryTranslatorImpl.getQueryString() );
      throw qe;
    }
    if ( o instanceof Integer ) {
      return new int[]{( ( Integer ) o ).intValue()};
    }
View Full Code Here

  protected void prepareArithmeticOperator(AST operator) throws SemanticException {
    ( ( OperatorNode ) operator ).initialize();
  }

  public static void panic() {
    throw new QueryException( "TreeWalker: panic" );
  }
View Full Code Here

  }

  private int[] getNamedParameterLocs(String name) throws QueryException {
    Object loc = customQuery.getNamedParameterBindPoints().get( name );
    if ( loc == null ) {
      throw new QueryException(
          "Named parameter does not appear in Query: " + name,
          customQuery.getSQL() );
    }
    if ( loc instanceof Integer ) {
      return new int[] { ((Integer) loc ).intValue() };
View Full Code Here

    Type type;
    try {
      type = TypeFactory.heuristicType( value.getClass().getName() );
    }
    catch ( MappingException me ) {
      throw new QueryException( me );
    }
    if ( type == null ) {
      throw new QueryException( QueryTranslator.ERROR_CANNOT_DETERMINE_TYPE + node.getText() );
    }
    try {
      LiteralType literalType = ( LiteralType ) type;
      Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
      node.setText( literalType.objectToSQLString( value, dialect ) );
    }
    catch ( Exception e ) {
      throw new QueryException( QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + node.getText(), e );
    }
    node.setDataType( type );
    node.setResolvedConstant( text );
  }
View Full Code Here

    }
    return type;
  }

  protected final QueryException propertyException(String propertyName) throws QueryException {
    return new QueryException( "could not resolve property: " + propertyName + " of: " + getEntityName() );
  }
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.