Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: JDBC getObject() and Oracle Object Types

Re: JDBC getObject() and Oracle Object Types

From: Paul Bethe <pbethe_at_wso.williams.edu>
Date: 5 Oct 2001 09:09:56 -0700
Message-ID: <d3233275.0110050809.5c6a1fe9@posting.google.com>


steven.wisener_at_carrierpoint.com (Steven Wisener) wrote in message news:<a00b3667.0109261345.2f63f1d9_at_posting.google.com>...
> I'm having problems retrieving Oracle object types from the database
> through JDBC. The Oracle object type is called SCHEMANAME.T_TEST_OBJ
> and it maps to the Java class com.carrierpoint.db.TestClass. Although
> the stored procedure that gets the object seems to succeed, the call
> to getObject to get the result fails. Here's the relevent code:
>
> public TestClass getTestObject(Long id)
> {
> Connection dbConn = null;
>
> try
> {
> dbConn = <blah> // get the connection, set up mapping etc.
>
> // Print out the type map for debugging purposes.
> Map typeMap = dbConn.getTypeMap();
> for (Iterator i = typeMap.keySet().iterator(); i.hasNext(); )
> {
> Object key = i.next();
> CPTrace.traceMessage("Key: " + key + ", "
> + "Value: " + typeMap.get(key));
> }
>
> // Setup the call
> String sql = "{?=call object_test_package.cp_get_test_obj(?)}";
> CallableStatement call = dbConn.prepareCall(sql);
> call.registerOutParameter(1,
> OracleTypes.STRUCT,
> "SCHEMANAME.T_TEST_OBJ");
> call.setLong(2, id.longValue());
>
> // Do it
> call.execute();
>
> // This will fail.
> return (TestClass) call.getObject(1);
> } catch (SQLException e)
> {
> e.printStackTrace();
> } finally
> {
> // Clean up.
> }
> }
>
> The output is:
>
> Key: SCHEMANAME.T_TEST_OBJ, Value: class com.carrierpoint.db.TestClass
> java.sql.SQLException: Inconsistent java and sql object types:
> SCHEMANAME.T_TEST_OBJ
> at java.lang.Throwable.fillInStackTrace(Native Method)
> at java.lang.Throwable.fillInStackTrace(Compiled Code)
> at java.lang.Throwable.<init>(Compiled Code)
> at java.lang.Exception.<init>(Compiled Code)
> at java.sql.SQLException.<init>(SQLException.java:43)
> at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
> at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:156)
> at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:775)
> at oracle.sql.STRUCT.toClass(STRUCT.java:443)
> at oracle.sql.STRUCT.toJdbc(STRUCT.java:378)
> at oracle.jdbc.driver.OracleStatement.getObjectValue(Compiled
> Code)
> at oracle.jdbc.driver.OracleStatement.getObjectValue(Compiled
> Code)
> at oracle.jdbc.driver.OracleCallableStatement.getObject(Compiled
> Code)
> (...)
>
> I am able to successfully write the object in the database through the
> custom Java class with another stored procedure. In addition, I have
> traces in the getSQLTypeName, readSQL, and writeSQL methods of my
> class, and none of them are traced before the above exception is
> thrown (they are traced when the object is written to the database,
> though).
>
> Any help would be greatly appreciated.
>
> --Steven

We have solved this problem have a further one. To solve this you need to add your class to the type map.. ...
Map typeMap = dbConn.getTypeMap ();
typeMap.put ("SCHEMANAME.T_TEST_OBJECT", TestClass.class); ..

then calling getObject will work
(assuming TestClass implements java.sql.SQLData)

OURPROBLEM:
When we define an object within an object When we read from the database it works - BUT within one objects readSQL call
we say
..
Movie favoriteMovie = (Movie)stream.getObject(); ..
where Movie is a Java class which implements SQLData, and Movie has also been added to the type map associated with its corresponding Oracle Object.

Anyone else experience this ??

Paul Received on Fri Oct 05 2001 - 11:09:56 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US