You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by "Robert S. Sfeir" <ro...@codepuccino.com> on 2004/01/31 00:52:46 UTC

PlatformDefaultImpl in RC5 throwing ClassCastException

I've hit a bug in RC5, which looks like it's been reported and fixed, so 
I checked out the code form CVS, made my build and ran the code and am 
still getting the exception.  I'm running this with Oracle using their 
oracle 1.4 jdbc driver.  (If there is a temporary workaround please let 
me know, this is a show stopper thanks)  I'd fix it but I'm lost as to 
why it's doing this exactly, the values that are being passed are 
correct (int, String, int)

The code causing it:  (checkedBrowsers is a String[])

            final PersistenceBroker broker = 
PersistenceBrokerFactory.defaultPersistenceBroker();
            final Criteria crit = new Criteria();
            crit.addIn( "browserID", Arrays.asList( checkedBrowsers ) );
            crit.addOrderBy( "browserName" , true);
            broker.beginTransaction();
            final Query query = QueryFactory.newQuery( 
BrowserBean.class, crit );
            broker.getCollectionByQuery( query );  <------  THIS CALL HERE
            broker.commitTransaction();

Seems after stepping around the code that the following code block is 
where things start to fail, and is throwing the RuntimeException.
(RsIterator.java line 204)
try
        {
            
setRsAndStmt(queryObject.performQuery(broker.serviceJdbcAccess())); 
<----  This one here
            /*
             * TODO: how does prefetchRelationships handle QueryBySQL 
instances? Is
             * it ok to pass query object?
             */
            prefetchRelationships(queryObject.getQuery());
            if (logger.isDebugEnabled())
            {
                logger.debug("RsIterator[" + queryObject + "] initialized");
            }
        }
        catch (RuntimeException e)
        {
            autoReleaseDbResources();
            throw e;
        }

The actual culprit it seems, for bizarre reasons is:
(PlatformDefaultImpl  line 255)
public void setObjectForStatement(PreparedStatement ps, int index, 
Object value, int sqlType)
            throws SQLException
    {
        if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
        {
            String s = (String) value;
            ps.setCharacterStream(index, new StringReader(s), s.length());
        }
        else
        {
            ps.setObject(index, value, sqlType); <--- Poops out right here
        }
    }

My full exception:
java.lang.ClassCastException
    at 
oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:2804)
    at 
oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:2905)
    at 
org.apache.ojb.broker.platforms.PlatformDefaultImpl.setObjectForStatement(PlatformDefaultImpl.java:265)
    at 
org.apache.ojb.broker.platforms.PlatformOracleImpl.setObjectForStatement(PlatformOracleImpl.java:171)
    at 
org.apache.ojb.broker.accesslayer.StatementManager.bindStatementValue(StatementManager.java:255)
    at 
org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementManager.java:358)
    at 
org.apache.ojb.broker.accesslayer.StatementManager.bindSelectionCriteria(StatementManager.java:455)
    at 
org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementManager.java:427)
    at 
org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementManager.java:400)
    at 
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(JdbcAccessImpl.java:317)
    at 
org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(RsQueryObject.java:113)
    at 
org.apache.ojb.broker.accesslayer.RsIterator.<init>(RsIterator.java:211)
    at 
org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(RsIteratorFactoryImpl.java:97)
    at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(PersistenceBrokerImpl.java:1606)
    at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(PersistenceBrokerImpl.java:1119)
    at 
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryReferenceBroker.java:143)
    at 
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryReferenceBroker.java:242)
    at 
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryReferenceBroker.java:262)
    at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(PersistenceBrokerImpl.java:1002)
    at 
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(DelegatingPersistenceBroker.java:322)
    at 
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(DelegatingPersistenceBroker.java:322)
    at 
com.codepuccino.tracker.sql.ojb.BrowserDAOImpl.selectForBatch(BrowserDAOImpl.java:151)
    at 
com.codepuccino.tracker.actions.BrowserAction.edit(BrowserAction.java:106)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at 
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
    at 
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
    at 
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    at 
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    at 
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
    at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
    at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
    at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
    at 
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
    at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
    at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
    at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
    at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
    at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
    at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
    at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
    at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
    at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
    at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
    at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
    at 
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)
    at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:805)
    at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:696)
    at 
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
    at 
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
    at java.lang.Thread.run(Thread.java:534)

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: [PATCH] PlatformDefaultImpl in RC5 throwing ClassCastException

Posted by Andy Malakov <an...@transdecisions.com>.
Hello Robert,

I am using Oracle 9.2.0 with RC5 and CVS Head. I do not see the same problem.

I have a question about your original e-mail:

    ps.setObject(index, value, sqlType); <--- Poops out right here

What is the value of sqlType in your case?

Here is decompiled oracle.jdbc.driver.OraclePreparedStatement.setObject  from  ojdbc14_g.jar (may be it will help?):

public synchronized void setObject(int paramIndex, Object x, int targetSqlType, int scale) throws SQLException {
        if(OracleLog.TRACE)
            OracleLog.print(this, 1, 16, 1, "OraclePreparedStatement.setObject(paramIndex=" + paramIndex + ", object,
targetSqlType=" + targetSqlType + ", scale=" + scale + ")");
        if(x == null && targetSqlType != 2002 && targetSqlType != 2008 && targetSqlType != 2003 && targetSqlType != 2007 &&
targetSqlType != 2006)
            setNull(paramIndex, targetSqlType);
        else
            switch(targetSqlType) {
            case 1: // '\001'
                if(x instanceof CHAR)
                    setCHAR(paramIndex, (CHAR)x);
                else
                    setString(paramIndex, (String)x);
                break;

            case 12: // '\f'
                setString(paramIndex, (String)x);
                break;

            case 999:
                setFixedCHAR(paramIndex, (String)x);
                break;

            case -1:
                setString(paramIndex, (String)x);
                break;

            case 2: // '\002'
                if(x instanceof NUMBER) {
                    setNUMBER(paramIndex, (NUMBER)x);
                    break;
                }
                if(x instanceof Byte) {
                    setByte(paramIndex, ((Byte)x).byteValue());
                    break;
                }
                if(x instanceof Short) {
                    setShort(paramIndex, ((Short)x).shortValue());
                    break;
                }
                if(x instanceof Integer) {
                    setInt(paramIndex, ((Integer)x).intValue());
                    break;
                }
                if(x instanceof Long) {
                    setLong(paramIndex, ((Long)x).longValue());
                    break;
                }
                if(x instanceof Float) {
                    setFloat(paramIndex, ((Float)x).floatValue());
                    break;
                }
                if(x instanceof Double)
                    setDouble(paramIndex, ((Double)x).doubleValue());
                else
                    setBigDecimal(paramIndex, (BigDecimal)x);
                break;

            case 3: // '\003'
                setBigDecimal(paramIndex, (BigDecimal)x);
                break;

            case -7:
                setBoolean(paramIndex, ((Boolean)x).booleanValue());
                break;

            case -6:
                setByte(paramIndex, ((Number)x).byteValue());
                break;

            case 5: // '\005'
                setShort(paramIndex, ((Number)x).shortValue());
                break;

            case 4: // '\004'
                setInt(paramIndex, ((Number)x).intValue());
                break;

            case -5:
                setLong(paramIndex, ((Number)x).longValue());
                break;

            case 6: // '\006'
            case 7: // '\007'
                setFloat(paramIndex, ((Number)x).floatValue());
                break;

            case 8: // '\b'
                setDouble(paramIndex, ((Number)x).doubleValue());
                break;

            case -2:
                if(x instanceof RAW)
                    setRAW(paramIndex, (RAW)x);
                else
                    setBytes(paramIndex, (byte[])x);
                break;

            case -3:
                setBytes(paramIndex, (byte[])x);
                break;

            case -4:
                setBytes(paramIndex, (byte[])x);
                break;

            case 91: // '['
                if(x instanceof DATE)
                    setDATE(paramIndex, (DATE)x);
                else
                    setDate(paramIndex, (Date)x);
                break;

            case 92: // '\\'
                setTime(paramIndex, (Time)x);
                break;

            case 93: // ']'
                if(x instanceof TIMESTAMP)
                    setTIMESTAMP(paramIndex, (TIMESTAMP)x);
                else
                    setTimestamp(paramIndex, (Timestamp)x);
                break;

            case -100:
                setTIMESTAMP(paramIndex, (TIMESTAMP)x);
                break;

            case -101:
                setTIMESTAMPTZ(paramIndex, (TIMESTAMPTZ)x);
                break;

            case -102:
                setTIMESTAMPLTZ(paramIndex, (TIMESTAMPLTZ)x);
                break;

            case -103:
                setINTERVALYM(paramIndex, (INTERVALYM)x);
                break;

            case -8:
                setROWID(paramIndex, (ROWID)x);
                break;

            case 2004:
                setBLOB(paramIndex, (BLOB)x);
                break;

            case 2005:
                setCLOB(paramIndex, (CLOB)x);
                break;

            case -13:
                setBFILE(paramIndex, (BFILE)x);
                break;

            case 2002:
            case 2008:
                setSTRUCT(paramIndex, STRUCT.toSTRUCT(x, connection));
                break;

            case 2003:
                setARRAY(paramIndex, (ARRAY)x);
                break;

            case 2007:
                setOPAQUE(paramIndex, (OPAQUE)x);
                break;

            case 2006:
                setREF(paramIndex, (REF)x);
                break;

            default:
                DBError.throwSqlException(4);
                break;
            }
    }

----- Original Message ----- 
From: "Robert S. Sfeir" <ro...@codepuccino.com>
To: "OJB Developers List" <oj...@db.apache.org>
Sent: Tuesday, February 03, 2004 8:57 AM
Subject: [PATCH] PlatformDefaultImpl in RC5 throwing ClassCastException


> :-\
>
> I guess no comments from the Oracle coders out there...  Can we then
> include this fix somehow so I don't have to keep 'fixing' my nightly
> builds, and certainly not 1.0?  This bug only affect Oracle impls.
> Tested it with Postgres and MySQL, ran JUnit tests and they all pass.
> Tested it with my app on various DBs, and things work as expected, no
> more ClassCastException.
>
> again the change is from:
> PlatformDefaultImpl line 255
>
> public void setObjectForStatement(PreparedStatement ps, int index,
> Object value, int sqlType)
>            throws SQLException
>    {
>        if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
>        {
>            String s = (String) value;
>            ps.setCharacterStream(index, new StringReader(s), s.length());
>        }
>        else
>        {
>            ps.setObject(index, value, sqlType);
>        }
>    }
>
> to:
>
> public void setObjectForStatement(PreparedStatement ps, int index,
> Object value, int sqlType)
>            throws SQLException
>    {
>        if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
>        {
>            String s = (String) value;
>            ps.setCharacterStream(index, new StringReader(s), s.length());
>        }
>       else if ((value instanceof String)) // setString() if value is
> String, not Object
>       {
>           ps.setString( index, value.toString());
>       }
>       else
>        {
>            ps.setObject(index, value, sqlType);
>        }
>    }
>
>
> Thanks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


[PATCH] PlatformDefaultImpl in RC5 throwing ClassCastException

Posted by "Robert S. Sfeir" <ro...@codepuccino.com>.
:-\

I guess no comments from the Oracle coders out there...  Can we then 
include this fix somehow so I don't have to keep 'fixing' my nightly 
builds, and certainly not 1.0?  This bug only affect Oracle impls.  
Tested it with Postgres and MySQL, ran JUnit tests and they all pass.  
Tested it with my app on various DBs, and things work as expected, no 
more ClassCastException.

again the change is from:
PlatformDefaultImpl line 255

public void setObjectForStatement(PreparedStatement ps, int index, 
Object value, int sqlType)
           throws SQLException
   {
       if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
       {
           String s = (String) value;
           ps.setCharacterStream(index, new StringReader(s), s.length());
       }
       else
       {
           ps.setObject(index, value, sqlType);
       }
   }

to:

public void setObjectForStatement(PreparedStatement ps, int index, 
Object value, int sqlType)
           throws SQLException
   {
       if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
       {
           String s = (String) value;
           ps.setCharacterStream(index, new StringReader(s), s.length());
       }
      else if ((value instanceof String)) // setString() if value is 
String, not Object
      {
          ps.setString( index, value.toString());
      }
      else
       {
           ps.setObject(index, value, sqlType);
       }
   }


Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: PlatformDefaultImpl in RC5 throwing ClassCastException

Posted by "Robert S. Sfeir" <ro...@codepuccino.com>.
HELLO?  Anyone? Buller?  Anything on this?  Is this the right solution?  
All the JUnit tests pass, and I've tested my code on postgres and mysql 
too, but these wouldn't break since this looks like an Oracle specific 
issue.

R


Robert S. Sfeir wrote:

> OOPS
>
> Robert S. Sfeir wrote:
>
>> Ok, for now (I don't know if this is the right fix, but I'm using it 
>> for now for myself)
>>
>> I changed the method to look like this:
>> PlatformDefaultImpl line 255
>>
>> public void setObjectForStatement(PreparedStatement ps, int index, 
>> Object value, int sqlType)
>>            throws SQLException
>>    {
>>        if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
>>        {
>>            String s = (String) value;
>>            ps.setCharacterStream(index, new StringReader(s), 
>> s.length());
>>        }
>
>
> this should be:
>        else if ((value instanceof String)) // Why are we setting 
> Object if value is a String?
>       {
>           ps.setString( index, value.toString());
>       }
>
>>
>>        if ((value instanceof String)) // Why are we setting Object if 
>> value is a String?
>>        {
>>            ps.setString( index, value.toString());
>>        }
>>        else
>>        {
>>            ps.setObject(index, value, sqlType);
>>        }
>>    }
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: PlatformDefaultImpl in RC5 throwing ClassCastException

Posted by "Robert S. Sfeir" <ro...@codepuccino.com>.
OOPS

Robert S. Sfeir wrote:

> Ok, for now (I don't know if this is the right fix, but I'm using it 
> for now for myself)
>
> I changed the method to look like this:
> PlatformDefaultImpl line 255
>
> public void setObjectForStatement(PreparedStatement ps, int index, 
> Object value, int sqlType)
>            throws SQLException
>    {
>        if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
>        {
>            String s = (String) value;
>            ps.setCharacterStream(index, new StringReader(s), s.length());
>        }

this should be:
        else if ((value instanceof String)) // Why are we setting Object 
if value is a String?
       {
           ps.setString( index, value.toString());
       }

>
>        if ((value instanceof String)) // Why are we setting Object if 
> value is a String?
>        {
>            ps.setString( index, value.toString());
>        }
>        else
>        {
>            ps.setObject(index, value, sqlType);
>        }
>    }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: PlatformDefaultImpl in RC5 throwing ClassCastException

Posted by "Robert S. Sfeir" <ro...@codepuccino.com>.
Ok, for now (I don't know if this is the right fix, but I'm using it for 
now for myself)

I changed the method to look like this:
PlatformDefaultImpl line 255

public void setObjectForStatement(PreparedStatement ps, int index, 
Object value, int sqlType)
            throws SQLException
    {
        if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
        {
            String s = (String) value;
            ps.setCharacterStream(index, new StringReader(s), s.length());
        }
        if ((value instanceof String)) // Why are we setting Object if 
value is a String?
        {
            ps.setString( index, value.toString());
        }
        else
        {
            ps.setObject(index, value, sqlType);
        }
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org