3

我正在将我的项目从 springboot 1.5.7 升级到 2.1.6 ,经过一些修改和更正编译错误后一切看起来都很好。

当我尝试一些测试用例来保存对象并使用@procedure 返回一列时,我看到以下错误

org.springframework.dao.InvalidDataAccessApiiUsageException: OUT/INOUT parameter not available: serviceRequestId; nested exception is java.lang.IllegalArgumentException: OUT/INOUT parameter not available

下面是我的存储库类:

 public interface ServiceRequestRepository extends CrudRepository<ServiceRequest, Long> {

    @Procedure(name = "saveServiceRequest")
    long saveServiceRequest(@Param("payloadIn") String payloadIn,
                            @Param("action") String action,
                            @Param("orderId") String orderId,
                            @Param("status") String status);
}

这是我的 ServiceRequestSnapshot

    @Entity
@Table(name = "service_request")
@NamedStoredProcedureQueries({
    @NamedStoredProcedureQuery(name = "saveServiceRequest",
        procedureName = "service_request_pkg.saveServiceRequest",
        parameters = {
            @StoredProcedureParameter(mode = ParameterMode.IN, name = "payloadIn", type = String.class),
            @StoredProcedureParameter(mode = ParameterMode.IN, name = "action", type = String.class),
            @StoredProcedureParameter(mode = ParameterMode.IN, name = "orderId", type = String.class),
            @StoredProcedureParameter(mode = ParameterMode.IN, name = "status", type = String.class),
            @StoredProcedureParameter(mode = ParameterMode.OUT, name = "serviceRequestId", type = Long.class)
        })
})
@Repository
public class ServiceRequest implements Serializable {
    @Id
    @GenericGenerator(name = "service_request_seq_gen", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = { @org.hibernate.annotations.Parameter(name = "sequence_name", value="service_request_seq") , @org.hibernate.annotations.Parameter(name = "allocationSize", value = "1")})
    @GeneratedValue(generator = "service_request_seq_gen")
    @Column(name = "SERVICE_REQUEST_SID")
    private long serviceRequestId;
    @Column(name = "payload_in")
    @Lob
    private String payloadIn;

这是我的程序:

    CREATE OR REPLACE PACKAGE service_request_pkg AS

  PROCEDURE saveServiceRequest(payload IN VARCHAR2, action IN VARCHAR2, orderId IN VARCHAR2, status IN VARCHAR2, serviceRequestId OUT number);

END service_request_pkg;


CREATE OR REPLACE PACKAGE BODY service_request_pkg AS

  PROCEDURE saveServiceRequest(payload IN VARCHAR2, action IN VARCHAR2, orderId IN VARCHAR2, status IN VARCHAR2, serviceRequestId OUT number) AS

    BEGIN

      insert into service_request (SERVICE_REQUEST_SID, PAYLOAD, ACTION, ORDER_ID, STATUS, CREATED_AT, UPDATED_AT) values (service_request_seq.nextval, payload, action, orderId, status, systimestamp, systimestamp) returning SERVICE_REQUEST_SID into serviceRequestId;
      commit;
    END saveServiceRequest;

END service_request_pkg;

请有任何建议,我被这个阻止了。

4

1 回答 1

10

可能在获取参数值之前已关闭连接。

使用 @Transactional 包装调用存储过程的 java 函数

于 2020-07-05T10:23:06.777 回答