[英]Passing a list of values to a stored procedure using JPA 2.1 / Hibernate 4
I have a stored procedure that takes in a list of strings (and follows limitations on stored procedures, according to Hibernate docs ): 我有一个存储过程,它接受一个字符串列表 (并遵循存储过程的限制, 根据Hibernate文档 ):
PROCEDURE count_active_esc(p_count OUT NUMBER, p_codes IN string_list);
where string_list
is a custom type: 其中
string_list
是自定义类型:
CREATE OR REPLACE TYPE string_list IS TABLE OF VARCHAR(100)
and want to to call it from JPA entity manager ( a new feature in JPA 2.1 ). 并希望从JPA实体管理器( JPA 2.1中的新功能)中调用它。
I tried to use an array: 我试图使用一个数组:
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
and got an exception: 并得到一个例外:
PLS-00306: wrong number or types of arguments in call to 'COUNT_ACTIVE_ESC'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
And if I pass in a list: 如果我传入一个列表:
StoredProcedreQuery query = entityManager.createNamedStoredProcedureQuery("count_active_esc");
query.registerStoredProcedureParameter("p_count", Integer.class, ParameterMode.OUT);
query.registerStoredProcedureParameter("p_codes", List.class, ParameterMode.IN); // <<<<< throws an exception
query.setParameter("p_codes", new ArrayList<String> {{ "AEST" }});
query.getOutputParameterValue("p_count");
it throws java.lang.IllegalArgumentException: Type cannot be null
它抛出
java.lang.IllegalArgumentException: Type cannot be null
Also adding query.setHint("org.hibernate.callable", "true")
didn't help. 另外添加
query.setHint("org.hibernate.callable", "true")
没有帮助。
What is the correct way of doing this in JPA or Hibernate? 在JPA或Hibernate中执行此操作的正确方法是什么? Is it at all possible without resorting to JDBC?
如果不诉诸JDBC,它是否可能?
Environment: JPA 2.1, Hibernate 4.3.5, Oracle 环境:JPA 2.1,Hibernate 4.3.5,Oracle
将Integer.class更改为Types.INTEGER
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.