内部错误:图像是集合图像,需要 Oracle 的 ADT
我正在尝试使用 spring-jdbc 调用 Oracle 数据库上的存储函数。
这是我试图调用的存储函数:
FUNCTION GET_RESOURCE_LIST RETURN RESOURCE_TAB;
接下来是resource_tab的定义
TYPE RESOURCE_TAB AS TABLE OF TRESOURCE;
接下来是tresource的定义
TYPE TRESOURCE AS OBJECT(
RESOURCE_ID NUMBER(10,0),
RESOURCE_NAME VARCHAR2(100)
)
调用代码
final SimpleJdbcCall call = new SimpleJdbcCall(idmJdbcTemplate).withFunctionName("get_resource_list").declareParameters(new SqlOutParameter(
"RETURN", OracleTypes.STRUCT,
"RESOURCE_TAB",
new SqlReturnType() {
@Override
public Object getTypeValue(CallableStatement cs, int paramIndex, int sqlType, String typeName) throws SQLException {
final Struct s = (Struct)cs.getObject(paramIndex);
final Object[] attr = s.getAttributes();
return attr[1];
}
}));
call.compile();
final Collection<String> resources = call.executeFunction(Collection.class);
最后是我收到的堆栈跟踪:
org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{? = call WVUID.IDM_REPO_MANUAL.GET_RESOURCE_LIST()}]; SQL state [99999]; error code [17001]; Internal Error: Image is a collection image,expecting ADT; nested exception is java.sql.SQLException: Internal Error: Image is a collection image,expecting ADT
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:969)
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1003)
Truncated. see log file for complete stacktrace
Caused By: java.sql.SQLException: Internal Error: Image is a collection image,expecting ADT
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)
Truncated. see log file for complete stacktrace
>
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:1015)
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:1)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:953)
... 62 more
I am trying to call a stored function on an oracle database with spring-jdbc.
This is the stored function I am trying to call:
FUNCTION GET_RESOURCE_LIST RETURN RESOURCE_TAB;
Next is the definition of resource_tab
TYPE RESOURCE_TAB AS TABLE OF TRESOURCE;
Next is the definition of tresource
TYPE TRESOURCE AS OBJECT(
RESOURCE_ID NUMBER(10,0),
RESOURCE_NAME VARCHAR2(100)
)
The calling code
final SimpleJdbcCall call = new SimpleJdbcCall(idmJdbcTemplate).withFunctionName("get_resource_list").declareParameters(new SqlOutParameter(
"RETURN", OracleTypes.STRUCT,
"RESOURCE_TAB",
new SqlReturnType() {
@Override
public Object getTypeValue(CallableStatement cs, int paramIndex, int sqlType, String typeName) throws SQLException {
final Struct s = (Struct)cs.getObject(paramIndex);
final Object[] attr = s.getAttributes();
return attr[1];
}
}));
call.compile();
final Collection<String> resources = call.executeFunction(Collection.class);
Last is the stack trace that I am receiving:
org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{? = call WVUID.IDM_REPO_MANUAL.GET_RESOURCE_LIST()}]; SQL state [99999]; error code [17001]; Internal Error: Image is a collection image,expecting ADT; nested exception is java.sql.SQLException: Internal Error: Image is a collection image,expecting ADT
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:969)
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1003)
Truncated. see log file for complete stacktrace
Caused By: java.sql.SQLException: Internal Error: Image is a collection image,expecting ADT
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)
Truncated. see log file for complete stacktrace
>
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:1015)
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:1)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:953)
... 62 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也遇到同样的问题,花了一天时间解决了。
考虑错误“图像是集合图像”,
它必须是
OracleTypes.ARRAY
,而不是OracleTypes.STRUCT
。关于您的 getTypeValue(...) 方法,我不能说它是否正确,但我将展示如何解析结果集(也许是和其他方式,请写出来):
另一种方式是
I have the same problem, and I spent a day to fix it.
Thinking about error "Image is a collection image", instead of
OracleTypes.STRUCT
it must beOracleTypes.ARRAY
.About your getTypeValue(...) method I can't say is it right or not, but I will show how parse the resultset (maybe it is and other way, please write it):
the another way is
问题在于输出参数的声明
返回类型(
TYPE RESOURCE_TAB AS TABLE OF TRESOURCE
)不是OracleTypes.STRUCT
(为对象类型保留),而是OracleTypes.ARRAY 。The problem is with the declaration of the output parameter
The return type (
TYPE RESOURCE_TAB AS TABLE OF TRESOURCE
) is not aOracleTypes.STRUCT
(that is reserved for Object Types) but anOracleTypes.ARRAY
.