内部错误:图像是集合图像,需要 Oracle 的 ADT

发布于 2024-11-09 18:18:33 字数 2962 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌路黄昏 2024-11-16 18:18:33

我也遇到同样的问题,花了一天时间解决了。
考虑错误“图像是集合图像”,

它必须是 OracleTypes.ARRAY,而不是 OracleTypes.STRUCT

关于您的 getTypeValue(...) 方法,我不能说它是否正确,但我将展示如何解析结果集(也许是和其他方式,请写出来):

@Override
public Object getTypeValue(CallableStatement cs, int paramIndex,
        int sqlType, String typeName) throws SQLException {

    ARRAY struct = (ARRAY) cs.getObject(paramIndex);

    ResultSet rs = struct.getResultSet();

    while (rs.next()) {
        Object rowIndex = rs.getObject(1);
        oracle.sql.STRUCT row = (oracle.sql.STRUCT) rs.getObject(2);
        if (row != null) {
            Object[] cols = row.getAttributes();
            System.out.print(rowIndex + ": ");
            for (Object col : cols) {
                System.out.print(col + " ");
            }
            System.out.println();
        }
    }

    return "construct your data structure above and return here";
}

另一种方式是

    @Override
public Object getTypeValue(CallableStatement cs, int paramIndex,
        int sqlType, String typeName) throws SQLException {

    ARRAY array = (ARRAY) cs.getObject(paramIndex);

    Object[] rows = (Object[])array.getArray();

    for(Object row : rows){
        Object[] cols = ((oracle.sql.STRUCT)row).getAttributes();
        for (Object col : cols) {
            System.out.print(col + " ");
        }
        System.out.println();

    }

    return "construct your data structure above and return here";
}

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 be OracleTypes.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):

@Override
public Object getTypeValue(CallableStatement cs, int paramIndex,
        int sqlType, String typeName) throws SQLException {

    ARRAY struct = (ARRAY) cs.getObject(paramIndex);

    ResultSet rs = struct.getResultSet();

    while (rs.next()) {
        Object rowIndex = rs.getObject(1);
        oracle.sql.STRUCT row = (oracle.sql.STRUCT) rs.getObject(2);
        if (row != null) {
            Object[] cols = row.getAttributes();
            System.out.print(rowIndex + ": ");
            for (Object col : cols) {
                System.out.print(col + " ");
            }
            System.out.println();
        }
    }

    return "construct your data structure above and return here";
}

the another way is

    @Override
public Object getTypeValue(CallableStatement cs, int paramIndex,
        int sqlType, String typeName) throws SQLException {

    ARRAY array = (ARRAY) cs.getObject(paramIndex);

    Object[] rows = (Object[])array.getArray();

    for(Object row : rows){
        Object[] cols = ((oracle.sql.STRUCT)row).getAttributes();
        for (Object col : cols) {
            System.out.print(col + " ");
        }
        System.out.println();

    }

    return "construct your data structure above and return here";
}
浅黛梨妆こ 2024-11-16 18:18:33

问题在于输出参数的声明

final SimpleJdbcCall call = new SimpleJdbcCall(idmJdbcTemplate).withFunctionName("get_resource_list").declareParameters(new SqlOutParameter(
    "RETURN", OracleTypes.STRUCT,
    "RESOURCE_TAB",
    new SqlReturnType() <etc>

返回类型(TYPE RESOURCE_TAB AS TABLE OF TRESOURCE)不是OracleTypes.STRUCT(为对象类型保留),而是OracleTypes.ARRAY 。

The problem is with the declaration of the output parameter

final SimpleJdbcCall call = new SimpleJdbcCall(idmJdbcTemplate).withFunctionName("get_resource_list").declareParameters(new SqlOutParameter(
    "RETURN", OracleTypes.STRUCT,
    "RESOURCE_TAB",
    new SqlReturnType() <etc>

The return type (TYPE RESOURCE_TAB AS TABLE OF TRESOURCE) is not a OracleTypes.STRUCT (that is reserved for Object Types) but an OracleTypes.ARRAY.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文