我有一个存储过程,它接受一个字符串列表(并遵循存储过程的限制,根据Hibernate文档):
PROCEDURE count_active_esc(p_count OUT NUMBER, p_codes IN string_list);
Run Code Online (Sandbox Code Playgroud)
string_list
自定义类型在哪里:
CREATE OR REPLACE TYPE string_list IS TABLE OF VARCHAR(100)
Run Code Online (Sandbox Code Playgroud)
并希望从JPA实体管理器(JPA 2.1中的新功能)中调用它.
我试图使用一个数组:
StoredProcedreQuery query = entityManager.createNamedStoredProcedureQuery("count_active_esc");
query.registerStoredProcedureParameter("p_count", Integer.class, ParameterMode.OUT);
query.registerStoredProcedureParameter("p_codes", String[].class, ParameterMode.IN);
query.setParameter("p_codes", new String[] { "AEST" });
query.getOutputParameterValue("p_count"); // <<<<< throws an exception
Run Code Online (Sandbox Code Playgroud)
并得到一个例外:
PLS-00306: wrong number or types of arguments in call to 'COUNT_ACTIVE_ESC'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Run Code Online (Sandbox Code Playgroud)
如果我传入一个列表:
StoredProcedreQuery query = entityManager.createNamedStoredProcedureQuery("count_active_esc");
query.registerStoredProcedureParameter("p_count", Integer.class, ParameterMode.OUT);
query.registerStoredProcedureParameter("p_codes", List.class, …
Run Code Online (Sandbox Code Playgroud) 来自java.lang.Exception
类javaDocs :
如果方法或构造函数的throws子句可以通过执行方法或构造函数抛出并在方法或构造函数边界外传播,则需要在方法或构造函数的throws子句中声明已检查的异常.
但请考虑以下代码:
package other;
public class CheckedExceptionHandling {
private static <E extends Exception> void throwException() throws E {
throw (E) new CheckedException2(); // unchecked cast warning
}
private static void setUncaughtExceptionHandler() {
Thread.currentThread().setUncaughtExceptionHandler((t, e) -> {
System.out.println("Unhandled exception: " + e.getClass()); // reports CheckedExceptionHandling$CheckedException2
});
}
public static void main(String[] args) /* no checked exceptions declared! */ {
setUncaughtExceptionHandler();
try {
CheckedExceptionHandling.<CheckedException1>throwException();
} catch (CheckedException1 e) {
System.out.println(e); // never gets here
}
}
// checked …
Run Code Online (Sandbox Code Playgroud)