I have a Oracle SP with the parameters as below
create type stringArray as table of varchar2(30)
/
CREATE OR REPLACE PROCEDURE create_deliverable
(
in_p_name varchar2,
in_p_filename stringArray
)AS
ret_ID number;
BEGIN
...
END;
/
while the "file name" is a string array in Oracle. The bean is defined as below:
@Data
public class BaseEntity {
private String name;
private String[] filename;
}
I want to pass the entire bean to Oracle stored procedure.
In my mapper.java
@Mapper
public interface BaseMapper {
void add(BaseEntity d);
}
In my BaseMapper.xml
<select id="add" statementType="CALLABLE" parameterType="BaseEntity">
call create_deliverable(
#{name},
#{filename,jdbcType=ARRAY, typeHandler=ArrayTypeHandler}
)
</select>
I attempted to write up a type handler to deal with the case. But I failed in the part to work it out.
Here's what's failed:
public class ArrayTypeHandler extends BaseTypeHandler<Object> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
throws SQLException {
Class<?> componentType = parameter.getClass().getComponentType();
String arrayTypeName = resolveTypeName(componentType);
Array array = ps.getConnection().createArrayOf(arrayTypeName, (Object[]) parameter);
ps.setArray(i, array);
array.free();
}
}
The failure is related to the part of "createArrayOf". It reads the arrayTypeName as VARCHAR, which is correct
Here's the error message:
Could not set parameters for mapping: ParameterMapping{property='filename', mode=IN, javaType=class java.util.ArrayList, jdbcType=ARRAY, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType ARRAY
Any input will be greatly appreciated.
Thanks
stringarrayto the question. It's a user-defined type, right?