when I yesterday switch to oracle I came across the same exception and I investigated a bit, and
found an unexpected situation in the PlatformOracleImpl.java
in the setObjectForStatement( .... ) method the sqlType was Type.INTEGER and the value was a String class
both arguments were passed to the PlatformDefaultImpl.java where they were passed into the PreparedStatement.
the String class seemed to be already wrong at this place, but a simple hack does work fine for me:
*** PlatformOracleImpl.java Sun May 4 14:08:14 2003
--- src/java/org/apache/ojb/broker/platforms/PlatformOracleImpl.java Thu Jun 5 09:17:58 2003
***************
*** 126,131 ****
--- 126,138 ----
ps.setLong(index, ((Integer) value).intValue());
}
+ else if (sqlType == Types.INTEGER && value instanceof String)
+ {
+ // workaround:
+ ps.setInt(index, Integer.parseInt( (String) value ) );
+ }
else
{
+ this.logger.debug( "using type " + sqlType + " for class " + value.getClass().getName()
+ + "(" + value + ")" );
super.setObjectForStatement(ps, index, value, sqlType);
}
maybe this also helps to find the real bug !!!
with best wishes Kristian
Brown, Melonie S. - Contractor wrote:
Has anybody else ran into this? This is a big problem for us, and I'm catching a lot of flack since I recommended we use OJB.
It appears that OJB is generating a getCollection query even though the code specifies a single object.
I'm not sure where to begin debugging, so any assistance would be greatly appreciated.
-------- Original Message -------- Subject: [RC3] Works with MySql, Fails with ClassCastException with Oracle Date: Thu, 29 May 2003 11:41:00 -0400 From: Brown, Melonie S. - Contractor <[EMAIL PROTECTED]> Reply-To: OJB Users List <[EMAIL PROTECTED]> Newsgroups: gmane.comp.jakarta.ojb.user
I have code that works perfectly fine in MySQL but crashes and dies against an Oracle database. I'm getting a java.lang.ClassCastException at GetCollectionByQuery which doesn't make sense since I'm calling broker.getObjectbyQuery. Also, no SQL statements show in the spy.log file. Suggestions would be greatly appreciated.
This is the code: public static RcioDB retrieveRcio(RcioDB sRcio) throws DataStoreException { PersistenceBroker broker = GetAccess.getPersistenceBroker();
try { broker.beginTransaction();
Criteria crit = new Criteria();
crit.addEqualTo( Constants.RCIO_ID, String.valueOf(sRcio.getRcio_ID()));
System.out.println("criteria set"); QueryByCriteria query = QueryFactory.newQuery(RcioDB.class, crit); System.out.println("query created");
Object theRcioToBeFetched = broker.getObjectByQuery(query); System.out.println("after fetch"); System.out.println(theRcioToBeFetched.getClass()); return (RcioDB)theRcioToBeFetched; } catch (Throwable t) { t.printStackTrace(); throw new DataStoreException(t.toString()); } finally { broker.close(); }
This is the output from the log:
criteria set query created [org.apache.ojb.broker.accesslayer.ConnectionManagerImpl] INFO: Rollback was called, do rollback on current connection [EMAIL PROTECTED] org.apache.ojb.broker.PersistenceBrokerException: java.lang.ClassCastException at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Persis tenceBrokerImpl.java:1467) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Persis tenceBrokerImpl.java:1496) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Persis tenceBrokerImpl.java:1485) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getObjectByQuery(Persistenc eBrokerImpl.java:1747) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByQuery(Dele gatingPersistenceBroker.java:271) at mil.army.forscom.tsamsweb.rcio.database.RcioCRUD.retrieveRcio(RcioCRUD.java: 131) at mil.army.forscom.tsamsweb.rcio.tests.InsertRciosTest.testInsertRcios(InsertR ciosTest.java:59) 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 junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRu nner.java:392) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner. java:276) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner .java:167) Caused by: java.lang.ClassCastException at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement .java:2804) at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement .java:2905) at com.p6spy.engine.spy.P6PreparedStatement.setObject(P6PreparedStatement.java: 282) at org.apache.ojb.broker.platforms.PlatformDefaultImpl.setObjectForStatement(Pl atformDefaultImpl.java:230) at org.apache.ojb.broker.platforms.PlatformOracleImpl.setObjectForStatement(Pla tformOracleImpl.java:130) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatementValue(Statem entManager.java:262) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementMa nager.java:296) at org.apache.ojb.broker.accesslayer.StatementManager.bindSelectionCriteria(Sta tementManager.java:474) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementMa nager.java:438) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementMa nager.java:410) at org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(JdbcAccessImpl .java:258) at org.apache.ojb.broker.accesslayer.RsIterator.<init>(RsIterator.java:199) at org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(RsIterator FactoryImpl.java:95) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Pers istenceBrokerImpl.java:2311) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Persis tenceBrokerImpl.java:1657) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Persis tenceBrokerImpl.java:1305) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Persis tenceBrokerImpl.java:1460)
My repository.xml:
<jdbc-connection-descriptor
platform="Oracle"
jdbc-level="2.0"
driver="com.p6spy.engine.spy.P6SpyDriver"
protocol="jdbc"
subprotocol="Oracle"
dbalias="thin:@machinestuff"
username="user"
password="password"
jcd-alias="default"
default-connection="true"
batch-mode="false"
useAutoCommit="1"
ignoreAutoCommitExceptions="false" >
<sequence-manager
className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">
</sequence-manager>
</jdbc-connection-descriptor>
The repository_user file: <class-descriptor class="foo.RcioDB" table="rcio" > <field-descriptor name="Rcio_ID" column="RCIO_ID" jdbc-type="INTEGER" primarykey="TRUE" autoincrement="false" indexed="true" /> <field-descriptor name="Rcio_Short_Name" column="RCIO_SHORT_NAME" jdbc-type="VARCHAR" primarykey="false" autoincrement="false" /> <field-descriptor name="Rcio_Desc" column="RCIO_DESC" jdbc-type="VARCHAR" primarykey="false" autoincrement="false" /> </class-descriptor>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
