You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Brian May <Br...@noaa.gov> on 2010/04/26 20:27:42 UTC
oracle.sql.STRUCT cannot be cast to oracle.sql.STRUCT
I am trying to map an Oracle type to a Java object using ibatis, but I
am confounded by a ClassCastException. It seems like I am using the
wrong version of the oracle.sql.STRUCT object, but I have no idea how to
find out what version of I should be using. I currently have Ibatis
2.3.4, ojdbc6, and Spring 3.0.2. Any help would be appreciated.
SqlMap:
<resultMap class="Object" id="attributeMap">
<result property="attribute" javaType="Object" jdbcType="ARRAY"
typeHandler="AttributeHandlerCallback"/>
</resultMap>
<select id="attribute" resultMap="attributeMap">
select
attribute_obj(0)
from dual
</select>
Dao:
public void getAttribute() {
queryForObject("attribute");
)
TypeHandler:
@Override
public Object getResult(final ResultGetter resultGetter) throws
SQLException {
Attribute atttribute = new attribute();
try {
final Object object = resultGetter.getObject();
System.out.println(object.getClass());
final STRUCT array =
(oracle.sql.STRUCT)resultGetter.getObject();
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
return attribute
}
Caused by: java.lang.ClassCastException: oracle.sql.STRUCT cannot be
cast to oracle.sql.STRUCT
at
gov.noaa.ncdc.cdo.services.dao.ibatis.typehandlers.AttributeHandlerCallback.getResult(DataHandlerCallback.java:30)
at
com.ibatis.sqlmap.engine.type.CustomTypeHandler.getResult(CustomTypeHandler.java:58)
at
com.ibatis.sqlmap.engine.mapping.result.ResultMap.getPrimitiveResultMappingValue(ResultMap.java:617)
at
com.ibatis.sqlmap.engine.mapping.result.ResultMap.getResults(ResultMap.java:345)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:384)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
... 46 more
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
Re: oracle.sql.STRUCT cannot be cast to oracle.sql.STRUCT
Posted by Brian May <Br...@noaa.gov>.
This is was the problem. I had a feeling it was a ClassLoader issue, but
the cause eluded me. I eventually found that I had the ojdbc6.jar in
both the tomcat/lib and web-inf/lib. So, even though the same class was
loaded they were not equal.
Thanks
cowwoc wrote:
> On 26/04/2010 3:48 PM, Guy Rouillier wrote:
>> Caused by: java.lang.ClassCastException: oracle.sql.STRUCT cannot be
>> cast to oracle.sql.STRUCT
>
> Sounds like a ClassLoader issue to me. The only time two classes
> with the same name are not equal to one another is when they're
> instantiated by different ClassLoaders.
>
> Gili
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
Re: oracle.sql.STRUCT cannot be cast to oracle.sql.STRUCT
Posted by cowwoc <co...@bbs.darktech.org>.
On 26/04/2010 3:48 PM, Guy Rouillier wrote:
> Caused by: java.lang.ClassCastException: oracle.sql.STRUCT cannot be
> cast to oracle.sql.STRUCT
Sounds like a ClassLoader issue to me. The only time two classes
with the same name are not equal to one another is when they're
instantiated by different ClassLoaders.
Gili
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
Re: oracle.sql.STRUCT cannot be cast to oracle.sql.STRUCT
Posted by Guy Rouillier <gu...@burntmail.com>.
Here is the example from the site:
1. ......
2. Statement stmt = connection.createStatement();
3. ResultSet rs= stmt.executeQuery("SELECT * FROM emp_table");
4. if(rs.next()) {
5. java.sql.Struct empType = (java.sql.Struct)rs.getObject(1);
6. System.out.println("Number of attributes "+
empType.getAttributes().length);
7. System.out.println("Name is " + empType.getAttributes()[0]);
8. System.out.println("Designation is " +
empType.getAttributes()[1]);
9. System.out.println("Department is " +
empType.getAttributes()[2]);
10. }
11. stmt.close();
12. ......
On 4/27/2010 7:15 AM, Brian May wrote:
> I would be happy to use a different method if it will be easier,but I
> can not access that link. I am told it is only available to
> ParnerNetwork Program Partners.
>
> Thanks
>
>
> Guy Rouillier wrote:
>> I've never had the need to use Oracle struct datatype, but I just used
>> Google to find this:
>>
>> http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/objects/ObjectTypes.html
>>
>>
>> The example is doing things differently than your code is. Perhaps
>> following the example will produce useful results.
>>
>> This appears to be a JDBC issue rather than an iBATIS issue.
>>
>> On 4/26/2010 2:27 PM, Brian May wrote:
>>> I am trying to map an Oracle type to a Java object using ibatis, but I
>>> am confounded by a ClassCastException. It seems like I am using the
>>> wrong version of the oracle.sql.STRUCT object, but I have no idea how to
>>> find out what version of I should be using. I currently have Ibatis
>>> 2.3.4, ojdbc6, and Spring 3.0.2. Any help would be appreciated.
>>>
>>> SqlMap:
>>> <resultMap class="Object" id="attributeMap">
>>> <result property="attribute" javaType="Object" jdbcType="ARRAY"
>>> typeHandler="AttributeHandlerCallback"/>
>>> </resultMap>
>>>
>>> <select id="attribute" resultMap="attributeMap">
>>> select
>>> attribute_obj(0)
>>> from dual
>>> </select>
>>>
>>> Dao:
>>> public void getAttribute() {
>>> queryForObject("attribute");
>>> )
>>>
>>> TypeHandler:
>>> @Override
>>> public Object getResult(final ResultGetter resultGetter) throws
>>> SQLException {
>>> Attribute atttribute = new attribute();
>>> try {
>>> final Object object = resultGetter.getObject();
>>> System.out.println(object.getClass());
>>> final STRUCT array = (oracle.sql.STRUCT)resultGetter.getObject();
>>> } catch (SQLException e) {
>>> // TODO: handle exception
>>> e.printStackTrace();
>>> }
>>>
>>> return attribute
>>> }
>>>
>>> Caused by: java.lang.ClassCastException: oracle.sql.STRUCT cannot be
>>> cast to oracle.sql.STRUCT
>>> at
>>> gov.noaa.ncdc.cdo.services.dao.ibatis.typehandlers.AttributeHandlerCallback.getResult(DataHandlerCallback.java:30)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.type.CustomTypeHandler.getResult(CustomTypeHandler.java:58)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.mapping.result.ResultMap.getPrimitiveResultMappingValue(ResultMap.java:617)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.mapping.result.ResultMap.getResults(ResultMap.java:345)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:384)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
>>>
>>>
>>> at
>>> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
>>>
>>>
>>> ... 46 more
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>
>>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>
--
Guy Rouillier
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
Re: oracle.sql.STRUCT cannot be cast to oracle.sql.STRUCT
Posted by Brian May <Br...@noaa.gov>.
I would be happy to use a different method if it will be easier,but I
can not access that link. I am told it is only available to
ParnerNetwork Program Partners.
Thanks
Guy Rouillier wrote:
> I've never had the need to use Oracle struct datatype, but I just used
> Google to find this:
>
> http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/objects/ObjectTypes.html
>
>
> The example is doing things differently than your code is. Perhaps
> following the example will produce useful results.
>
> This appears to be a JDBC issue rather than an iBATIS issue.
>
> On 4/26/2010 2:27 PM, Brian May wrote:
>> I am trying to map an Oracle type to a Java object using ibatis, but I
>> am confounded by a ClassCastException. It seems like I am using the
>> wrong version of the oracle.sql.STRUCT object, but I have no idea how to
>> find out what version of I should be using. I currently have Ibatis
>> 2.3.4, ojdbc6, and Spring 3.0.2. Any help would be appreciated.
>>
>> SqlMap:
>> <resultMap class="Object" id="attributeMap">
>> <result property="attribute" javaType="Object" jdbcType="ARRAY"
>> typeHandler="AttributeHandlerCallback"/>
>> </resultMap>
>>
>> <select id="attribute" resultMap="attributeMap">
>> select
>> attribute_obj(0)
>> from dual
>> </select>
>>
>> Dao:
>> public void getAttribute() {
>> queryForObject("attribute");
>> )
>>
>> TypeHandler:
>> @Override
>> public Object getResult(final ResultGetter resultGetter) throws
>> SQLException {
>> Attribute atttribute = new attribute();
>> try {
>> final Object object = resultGetter.getObject();
>> System.out.println(object.getClass());
>> final STRUCT array = (oracle.sql.STRUCT)resultGetter.getObject();
>> } catch (SQLException e) {
>> // TODO: handle exception
>> e.printStackTrace();
>> }
>>
>> return attribute
>> }
>>
>> Caused by: java.lang.ClassCastException: oracle.sql.STRUCT cannot be
>> cast to oracle.sql.STRUCT
>> at
>> gov.noaa.ncdc.cdo.services.dao.ibatis.typehandlers.AttributeHandlerCallback.getResult(DataHandlerCallback.java:30)
>>
>>
>> at
>> com.ibatis.sqlmap.engine.type.CustomTypeHandler.getResult(CustomTypeHandler.java:58)
>>
>>
>> at
>> com.ibatis.sqlmap.engine.mapping.result.ResultMap.getPrimitiveResultMappingValue(ResultMap.java:617)
>>
>>
>> at
>> com.ibatis.sqlmap.engine.mapping.result.ResultMap.getResults(ResultMap.java:345)
>>
>>
>> at
>> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:384)
>>
>>
>> at
>> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
>>
>>
>> at
>> com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
>>
>>
>> at
>> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
>>
>>
>> at
>> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
>>
>>
>> ... 46 more
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
Re: oracle.sql.STRUCT cannot be cast to oracle.sql.STRUCT
Posted by Guy Rouillier <gu...@burntmail.com>.
I've never had the need to use Oracle struct datatype, but I just used
Google to find this:
http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/objects/ObjectTypes.html
The example is doing things differently than your code is. Perhaps
following the example will produce useful results.
This appears to be a JDBC issue rather than an iBATIS issue.
On 4/26/2010 2:27 PM, Brian May wrote:
> I am trying to map an Oracle type to a Java object using ibatis, but I
> am confounded by a ClassCastException. It seems like I am using the
> wrong version of the oracle.sql.STRUCT object, but I have no idea how to
> find out what version of I should be using. I currently have Ibatis
> 2.3.4, ojdbc6, and Spring 3.0.2. Any help would be appreciated.
>
> SqlMap:
> <resultMap class="Object" id="attributeMap">
> <result property="attribute" javaType="Object" jdbcType="ARRAY"
> typeHandler="AttributeHandlerCallback"/>
> </resultMap>
>
> <select id="attribute" resultMap="attributeMap">
> select
> attribute_obj(0)
> from dual
> </select>
>
> Dao:
> public void getAttribute() {
> queryForObject("attribute");
> )
>
> TypeHandler:
> @Override
> public Object getResult(final ResultGetter resultGetter) throws
> SQLException {
> Attribute atttribute = new attribute();
> try {
> final Object object = resultGetter.getObject();
> System.out.println(object.getClass());
> final STRUCT array = (oracle.sql.STRUCT)resultGetter.getObject();
> } catch (SQLException e) {
> // TODO: handle exception
> e.printStackTrace();
> }
>
> return attribute
> }
>
> Caused by: java.lang.ClassCastException: oracle.sql.STRUCT cannot be
> cast to oracle.sql.STRUCT
> at
> gov.noaa.ncdc.cdo.services.dao.ibatis.typehandlers.AttributeHandlerCallback.getResult(DataHandlerCallback.java:30)
>
> at
> com.ibatis.sqlmap.engine.type.CustomTypeHandler.getResult(CustomTypeHandler.java:58)
>
> at
> com.ibatis.sqlmap.engine.mapping.result.ResultMap.getPrimitiveResultMappingValue(ResultMap.java:617)
>
> at
> com.ibatis.sqlmap.engine.mapping.result.ResultMap.getResults(ResultMap.java:345)
>
> at
> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:384)
>
> at
> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
>
> at
> com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
>
> at
> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
>
> at
> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
>
> ... 46 more
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>
--
Guy Rouillier
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org