These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with hibernate SQLNative
PostPosted: Fri Jul 25, 2008 10:36 am 
Newbie

Joined: Fri Jul 25, 2008 10:19 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0

Full stack trace of any exception that occurs:

Code:
25/07/2008 11:24:59 org.hibernate.type.NullableType nullSafeGet
INFO: could not read column value from result set: CL08_RESIPRO; String index out of range: 0
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
   at java.lang.String.charAt(Unknown Source)
   at org.hibernate.type.CharacterType.get(CharacterType.java:29)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:189)
   at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:474)
   at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:420)
   at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:317)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
   at org.hibernate.loader.Loader.doQuery(Loader.java:701)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
   at org.hibernate.loader.Loader.doList(Loader.java:2220)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
   at org.hibernate.loader.Loader.list(Loader.java:2099)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
   at br.com.consist.databridge.broker.ClienteDBBroker.getListaSincronizar(ClienteDBBroker.java:174)
   at br.com.consist.databridge.service.ClienteDBService.getListaSincronizar(ClienteDBService.java:50)
   at br.com.consist.databridge.ws.ClienteDBWebService.getXML(ClienteDBWebService.java:120)
   at UseWSDB.main(UseWSDB.java:190)


Name and version of the database you are using:

Adabas, but there isn't yet a dialect made, perhaps I tried extends dialect and make it. Here is the code:
Code:
package br.com.consist.hibernate.dialect;

import java.sql.Types;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.CallableStatement;
import org.hibernate.sql.CaseFragment;
import org.hibernate.sql.ANSICaseFragment;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.OracleJoinFragment;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.dialect.function.NoArgSQLFunction;
import org.hibernate.dialect.function.VarArgsSQLFunction;
import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.dialect.function.NvlFunction;
import org.hibernate.dialect.Dialect;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.util.ReflectHelper;
import org.hibernate.exception.ViolatedConstraintNameExtracter;
import org.hibernate.exception.TemplatedViolatedConstraintNameExtracter;
import org.hibernate.exception.JDBCExceptionHelper;

public class AdabasDialect extends Dialect {

   public AdabasDialect() {
      
      super();
      
      registerVarcharTypes();
      registerCharacterTypeMappings();
      registerNumericTypeMappings();
      registerDateTimeTypeMappings();
      registerLargeObjectTypeMappings();
      registerReverseHibernateTypeMappings();
      registerFunctions();
      registerDefaultProperties();
      
      getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);      
      
   }
   
   protected void registerVarcharTypes() {
      
      registerColumnType( Types.VARCHAR, "longtext" );
      registerColumnType( Types.VARCHAR, 16777215, "mediumtext" );
      registerColumnType( Types.VARCHAR, 65535, "text" );      
      registerColumnType( Types.VARCHAR, 255, "varchar($l)" );
      registerColumnType( Types.VARCHAR, "char");      
      System.out.println("HELLO WORLD");
   }
   
   protected void registerCharacterTypeMappings() {
      registerColumnType( Types.CHAR, "char($p)" );
//      registerColumnType( Types.CHAR, "char(20)" );
      registerColumnType( Types.VARCHAR, 4000, "varchar2($l)" );
      registerColumnType( Types.VARCHAR, "long" );
   }

   protected void registerNumericTypeMappings() {
      registerColumnType( Types.BIT, "number(1,0)" );
      registerColumnType( Types.BIGINT, "number(19,0)" );
      registerColumnType( Types.SMALLINT, "number(5,0)" );
      registerColumnType( Types.TINYINT, "number(3,0)" );
      registerColumnType( Types.INTEGER, "number(10,0)" );
      registerColumnType( Types.FLOAT, "float" );
      registerColumnType( Types.DOUBLE, "double precision" );
      registerColumnType( Types.NUMERIC, "number($p,$s)" );
      registerColumnType( Types.DECIMAL, "number($p,$s)" );
   }

   protected void registerDateTimeTypeMappings() {
      registerColumnType( Types.DATE, "date" );
      registerColumnType( Types.TIME, "date" );
      registerColumnType( Types.TIMESTAMP, "timestamp" );
   }

   protected void registerLargeObjectTypeMappings() {
      registerColumnType( Types.VARBINARY, 2000, "raw($l)" );
      registerColumnType( Types.VARBINARY, "long raw" );

      //registerColumnType( Types.BLOB, "blob" );
      //registerColumnType( Types.CLOB, "clob" );
   }

   public CaseFragment createCaseFragment() {
      // Oracle did add support for ANSI CASE statements in 9i
      return new ANSICaseFragment();
   }
   
   protected void registerReverseHibernateTypeMappings() {
   }

   protected void registerFunctions() {
      registerFunction( "abs", new StandardSQLFunction("abs") );
      registerFunction( "sign", new StandardSQLFunction("sign", Hibernate.INTEGER) );

      registerFunction( "acos", new StandardSQLFunction("acos", Hibernate.DOUBLE) );
      registerFunction( "asin", new StandardSQLFunction("asin", Hibernate.DOUBLE) );
      registerFunction( "atan", new StandardSQLFunction("atan", Hibernate.DOUBLE) );
      registerFunction( "cos", new StandardSQLFunction("cos", Hibernate.DOUBLE) );
      registerFunction( "cosh", new StandardSQLFunction("cosh", Hibernate.DOUBLE) );
      registerFunction( "exp", new StandardSQLFunction("exp", Hibernate.DOUBLE) );
      registerFunction( "ln", new StandardSQLFunction("ln", Hibernate.DOUBLE) );
      registerFunction( "sin", new StandardSQLFunction("sin", Hibernate.DOUBLE) );
      registerFunction( "sinh", new StandardSQLFunction("sinh", Hibernate.DOUBLE) );
      registerFunction( "stddev", new StandardSQLFunction("stddev", Hibernate.DOUBLE) );
      registerFunction( "sqrt", new StandardSQLFunction("sqrt", Hibernate.DOUBLE) );
      registerFunction( "tan", new StandardSQLFunction("tan", Hibernate.DOUBLE) );
      registerFunction( "tanh", new StandardSQLFunction("tanh", Hibernate.DOUBLE) );
      registerFunction( "variance", new StandardSQLFunction("variance", Hibernate.DOUBLE) );

      registerFunction( "round", new StandardSQLFunction("round") );
      registerFunction( "trunc", new StandardSQLFunction("trunc") );
      registerFunction( "ceil", new StandardSQLFunction("ceil") );
      registerFunction( "floor", new StandardSQLFunction("floor") );

      registerFunction( "chr", new StandardSQLFunction("chr", Hibernate.CHARACTER) );      
      registerFunction( "initcap", new StandardSQLFunction("initcap") );
      registerFunction( "lower", new StandardSQLFunction("lower") );
      registerFunction( "ltrim", new StandardSQLFunction("ltrim") );
      registerFunction( "rtrim", new StandardSQLFunction("rtrim") );
      registerFunction( "soundex", new StandardSQLFunction("soundex") );
      registerFunction( "upper", new StandardSQLFunction("upper") );
      registerFunction( "ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER) );
      registerFunction( "length", new StandardSQLFunction("length", Hibernate.LONG) );

      registerFunction( "to_char", new StandardSQLFunction("to_char", Hibernate.STRING) );
      registerFunction( "to_date", new StandardSQLFunction("to_date", Hibernate.TIMESTAMP) );

      registerFunction( "current_date", new NoArgSQLFunction("current_date", Hibernate.DATE, false) );
      registerFunction( "current_time", new NoArgSQLFunction("current_timestamp", Hibernate.TIME, false) );
      registerFunction( "current_timestamp", new NoArgSQLFunction("current_timestamp", Hibernate.TIMESTAMP, false) );

      registerFunction( "lastday", new StandardSQLFunction("lastday", Hibernate.DATE) );
      registerFunction( "sysdate", new NoArgSQLFunction("sysdate", Hibernate.DATE, false) );
      registerFunction( "systimestamp", new NoArgSQLFunction("systimestamp", Hibernate.TIMESTAMP, false) );
      registerFunction( "uid", new NoArgSQLFunction("uid", Hibernate.INTEGER, false) );
      registerFunction( "user", new NoArgSQLFunction("user", Hibernate.STRING, false) );

      registerFunction( "rowid", new NoArgSQLFunction("rowid", Hibernate.LONG, false) );
      //registerFunction( "rownum", new NoArgSQLFunction("rownum", Hibernate.LONG, false) );
      registerFunction( "rowno", new NoArgSQLFunction("rowno", Hibernate.LONG, false) );

      // Multi-param string dialect functions...
      registerFunction( "concat", new VarArgsSQLFunction(Hibernate.STRING, "", "||", "") );
      registerFunction( "instr", new StandardSQLFunction("instr", Hibernate.INTEGER) );
      registerFunction( "instrb", new StandardSQLFunction("instrb", Hibernate.INTEGER) );
      registerFunction( "lpad", new StandardSQLFunction("lpad", Hibernate.STRING) );
      registerFunction( "replace", new StandardSQLFunction("replace", Hibernate.STRING) );
      registerFunction( "rpad", new StandardSQLFunction("rpad", Hibernate.STRING) );
      registerFunction( "substr", new StandardSQLFunction("substr", Hibernate.STRING) );
      registerFunction( "substrb", new StandardSQLFunction("substrb", Hibernate.STRING) );
      registerFunction( "translate", new StandardSQLFunction("translate", Hibernate.STRING) );

      registerFunction( "substring", new StandardSQLFunction( "substr", Hibernate.STRING ) );
      registerFunction( "locate", new SQLFunctionTemplate( Hibernate.INTEGER, "instr(?2,?1)" ) );
      registerFunction( "bit_length", new SQLFunctionTemplate( Hibernate.INTEGER, "vsize(?1)*8" ) );
      registerFunction( "coalesce", new NvlFunction() );

      // Multi-param numeric dialect functions...
      registerFunction( "atan2", new StandardSQLFunction("atan2", Hibernate.FLOAT) );
      registerFunction( "log", new StandardSQLFunction("log", Hibernate.INTEGER) );
      registerFunction( "mod", new StandardSQLFunction("mod", Hibernate.INTEGER) );
      registerFunction( "nvl", new StandardSQLFunction("nvl") );
      registerFunction( "nvl2", new StandardSQLFunction("nvl2") );
      registerFunction( "power", new StandardSQLFunction("power", Hibernate.FLOAT) );

      // Multi-param date dialect functions...
      registerFunction( "add_months", new StandardSQLFunction("add_months", Hibernate.DATE) );
      registerFunction( "months_between", new StandardSQLFunction("months_between", Hibernate.FLOAT) );
      registerFunction( "next_day", new StandardSQLFunction("next_day", Hibernate.DATE) );

      registerFunction( "str", new StandardSQLFunction("to_char", Hibernate.STRING) );
   }

   protected void registerDefaultProperties() {
      getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "true" );
      getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
      // Oracle driver reports to support getGeneratedKeys(), but they only
      // support the version taking an array of the names of the columns to
      // be returned (via its RETURNING clause).  No other driver seems to
      // support this overloaded version.
      getDefaultProperties().setProperty( Environment.USE_GET_GENERATED_KEYS, "false" );
   }


   // features which change between 8i, 9i, and 10g ~~~~~~~~~~~~~~~~~~~~~~~~~~

   /**
    * Support for the oracle proprietary join syntax...
    *
    * @return The orqacle join fragment
    */
   public JoinFragment createOuterJoinFragment() {
      return new OracleJoinFragment();
   }

   /**
    * Map case support to the Oracle DECODE function.  Oracle did not
    * add support for CASE until 9i.
    *
    * @return The oracle CASE -> DECODE fragment
    */
   /*
   public CaseFragment createCaseFragment() {
      return new DecodeCaseFragment();
   }
   */

   public String getLimitString(String sql, boolean hasOffset) {
      sql = sql.trim();
      boolean isForUpdate = false;
      if ( sql.toLowerCase().endsWith(" for update") ) {
         sql = sql.substring( 0, sql.length()-11 );
         isForUpdate = true;
      }

      StringBuffer pagingSelect = new StringBuffer( sql.length()+100 );
      if (hasOffset) {
         //pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
         pagingSelect.append("select * from ( select row_.*, rowno rowno_ from ( ");
      }
      else {
         pagingSelect.append("select * from ( ");
      }
      pagingSelect.append(sql);
      if (hasOffset) {
         //pagingSelect.append(" ) row_ ) where rownum_ <= ? and rownum_ > ?");
         pagingSelect.append(" ) row_ ) where rowno_ <= ? and rowno_ > ?");
      }
      else {
         //pagingSelect.append(" ) where rownum <= ?");
         pagingSelect.append(" ) where rowno <= ?");
      }

      if ( isForUpdate ) {
         pagingSelect.append( " for update" );
      }

      return pagingSelect.toString();
   }

   /**
    * Allows access to the basic {@link Dialect#getSelectClauseNullString}
    * implementation...
    *
    * @param sqlType The {@link java.sql.Types} mapping type code
    * @return The appropriate select cluse fragment
    */
   public String getSelectClauseNullString(int sqlType) {
      return getBasicSelectClauseNullString( sqlType );
   }

   
   public String getCurrentTimestampSelectString() {
      //return "select systimestamp from dual";
      return "select now() from dual";
   }

   public String getCurrentTimestampSQLFunctionName() {
      // the standard SQL function name is current_timestamp...
      return "current_timestamp";
   }
   
   
   public String getBasicSelectClauseNullString(int sqlType) {
      return super.getSelectClauseNullString( sqlType );
   }

   /*
   public String getSelectClauseNullString(int sqlType) {
      switch(sqlType) {
         case Types.VARCHAR:
         case Types.CHAR:
            return "to_char(null)";
         case Types.DATE:
         case Types.TIMESTAMP:
         case Types.TIME:
            return "to_date(null)";
         default:
            return "to_number(null)";
      }
   }

   public String getCurrentTimestampSelectString() {
      return "select sysdate from dual";
   }

   public String getCurrentTimestampSQLFunctionName() {
      return "sysdate";
   }
   */


   // features which remain constant across 8i, 9i, and 10g ~~~~~~~~~~~~~~~~~~

   public String getAddColumnString() {
      return "add";
   }

   public String getSequenceNextValString(String sequenceName) {
      return "select " + getSelectSequenceNextValString( sequenceName ) + " from dual";
   }

   public String getSelectSequenceNextValString(String sequenceName) {
      return sequenceName + ".nextval";
   }

   public String getCreateSequenceString(String sequenceName) {
      return "create sequence " + sequenceName; //starts with 1, implicitly
   }

   public String getDropSequenceString(String sequenceName) {
      return "drop sequence " + sequenceName;
   }

   public String getCascadeConstraintsString() {
      return " cascade constraints";
   }

   public boolean dropConstraints() {
      return false;
   }

   public String getForUpdateNowaitString() {
      return " for update nowait";
   }

   public boolean supportsSequences() {
      return true;
   }

   public boolean supportsPooledSequences() {
      return true;
   }

   public boolean supportsLimit() {
      return true;
   }

   public String getForUpdateString(String aliases) {
      return getForUpdateString() + " of " + aliases;
   }

   public String getForUpdateNowaitString(String aliases) {
      return getForUpdateString() + " of " + aliases + " nowait";
   }

   public boolean bindLimitParametersInReverseOrder() {
      return true;
   }

   public boolean useMaxForLimit() {
      return true;
   }

   public boolean forUpdateOfColumns() {
      return true;
   }

   public String getQuerySequencesString() {
      return "select sequence_name from user_sequences";
   }

   public String getSelectGUIDString() {
      return "select rawtohex(sys_guid()) from dual";
   }

   public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() {
        return EXTRACTER;
   }

   private static ViolatedConstraintNameExtracter EXTRACTER = new TemplatedViolatedConstraintNameExtracter() {

      /**
       * Extract the name of the violated constraint from the given SQLException.
       *
       * @param sqle The exception that was the result of the constraint violation.
       * @return The extracted constraint name.
       */
      public String extractConstraintName(SQLException sqle) {
         int errorCode = JDBCExceptionHelper.extractErrorCode(sqle);
         if ( errorCode == 1 || errorCode == 2291 || errorCode == 2292 ) {
            return extractUsingTemplate( "constraint (", ") violated", sqle.getMessage() );
         }
         else if ( errorCode == 1400 ) {
            // simple nullability constraint
            return null;
         }
         else {
            return null;
         }
      }

   };

   // not final-static to avoid possible classcast exceptions if using different oracle drivers.
   int oracletypes_cursor_value = 0;
   public int registerResultSetOutParameter(java.sql.CallableStatement statement,int col) throws SQLException {
      if(oracletypes_cursor_value==0) {
         try {
            Class types = ReflectHelper.classForName("oracle.jdbc.driver.OracleTypes");
            oracletypes_cursor_value = types.getField("CURSOR").getInt(types.newInstance());
         } catch (Exception se) {
            throw new HibernateException("Problem while trying to load or access OracleTypes.CURSOR value",se);
         }
      }
      //   register the type of the out param - an Oracle specific type
      statement.registerOutParameter(col, oracletypes_cursor_value);
      col++;
      return col;
   }

   public ResultSet getResultSet(CallableStatement ps) throws SQLException {
      ps.execute();
      return ( ResultSet ) ps.getObject( 1 );
   }

   public boolean supportsUnionAll() {
      return true;
   }

   public boolean supportsCommentOn() {
      return true;
   }

   public boolean supportsTemporaryTables() {
      return true;
   }

   public String generateTemporaryTableName(String baseTableName) {
      String name = super.generateTemporaryTableName(baseTableName);
      return name.length() > 30 ? name.substring( 1, 30 ) : name;
   }

   public String getCreateTemporaryTableString() {
      return "create global temporary table";
   }

   public String getCreateTemporaryTablePostfix() {
      return "on commit delete rows";
   }

   public boolean dropTemporaryTableAfterUse() {
      return false;
   }

   public boolean supportsCurrentTimestampSelection() {
      return true;
   }

   public boolean isCurrentTimestampSelectStringCallable() {
      return false;
   }

   public boolean supportsEmptyInList() {
      return false;
   }

   public boolean supportsExistsInSelect() {
      return false;
   }

   

}



Problem's description

Morning!

The database I use has a type which is char, when my field is null and I do a search with SQLNative into the Hibernate, comes the following error:

Could not read column value from result set: CL08_RESIPRO; String index out of range: 0

There into my table, the type char is like char(1)

Someone can help please??

thanks!

valeu!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.