0
存儲功能,我有以下類型的PostgreSQL:春天 - 調用複雜的結果
CREATE TYPE TR_PERSON AS (
i_out integer,
str_out text
);
而且我已存儲的函數返回我喜歡的類型:
CREATE OR REPLACE FUNCTION test_function(id int)
RETURNS TR_PERSON
AS $$
SELECT $1, text('Alice')
$$ LANGUAGE SQL;
我試圖使用從SimpleJdbcCall時春天從數據庫獲取數據:
SimpleJdbcCall call = new SimpleJdbcCall(jdbcTemplate)
.withFunctionName("test_function");
SqlParameterSource in = new MapSqlParameterSource().addValue("id", 1);
try {
TRPerson result = call.executeFunction(TRPerson.class, in);
} catch (DataAccessException e) {
logger.log(Level.SEVERE, "call failed", e);
}
然後,我得到異常:
SEVERE: call failed
org.springframework.dao.InvalidDataAccessApiUsageException: Required input parameter 'i_out' is missing
at org.springframework.jdbc.core.CallableStatementCreatorFactory$CallableStatementCreatorImpl.createCallableStatement(CallableStatementCreatorFactory.java:209)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1014)
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1070)
at org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:387)
at org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:350)
at org.springframework.jdbc.core.simple.SimpleJdbcCall.executeFunction(SimpleJdbcCall.java:154)
我不明白爲什麼i_out被標記爲輸入類型。我做錯了什麼?
SimpleJdbcCall是否適合我的需要?
存儲函數和複雜類型結果的最佳做法是什麼?
我非常感謝一些骨架代碼來捕捉管道。