【发布时间】:2015-10-22 16:22:46
【问题描述】:
我正在尝试使用 JPA 2.1 @NamedStoredProcedureQuery 调用存储过程。 我的实体类中有以下注释。
问题是如果我将模式声明为 ParameterMode.IN,我将无法传递空值。只有当我将它声明为 ParameterMode.INOUT 时才能传递空值。
实体
@NamedStoredProcedureQuery(name = "employee", procedureName = "myProcedure", resultClasses = Employee.class, parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = "EMPLOYEE_PHONE", type = String.class),
@StoredProcedureParameter(mode = ParameterMode.INOUT, name = "CITY", type = String.class)
存储库
public Long createOrUpdateEmployee(Employee employee) throws EbaDataException {
StoredProcedureQuery query = entityManager.createNamedStoredProcedureQuery("employee");
query.setParameter("EMPLOYEE_PHONE", employee.getName());
query.setParameter("CITY", employee.getCity());
query.execute();
}
例如,如果我使用 ParameterMode.IN 为索引 2 (CITY) 传递 null,则会收到此异常。
Caused by: java.sql.SQLException: Missing IN or OUT parameter at index:: 2
【问题讨论】:
标签: java hibernate jpa stored-procedures jpa-2.1