【问题标题】:How Execute Stored Procedure using JPA annotation @NamedStoredProcedureQuery如何使用 JPA 注释 @NamedStoredProcedureQuery 执行存储过程
【发布时间】:2020-01-23 21:32:30
【问题描述】:

如何使用@NamedStoredProcedureQuery 转换此过程执行?

我有这个SQL,没关系!

SQL(没问题):




USE [INTEGRADOR]
GO

DECLARE @return_value int

EXEC    @return_value = [dbo].[SP_VW_PEDIDOSDECOMPRA_SGM]
        @CODIGO = 71648

SELECT  'Return Value' = @return_value 

GO


在 Java 中我试试这个,但不工作。 idUsuarioAutenticado 是 @CODIGO = 71648


JAVA(编译时出错):


@NamedStoredProcedureQuery(
            name = "listarComprasMicrosigaProc", 
            procedureName = "INTEGRADOR.DBO.SP_VW_PEDIDOSDECOMPRA_SGM", 
            resultClasses = AcompanhamentoCompraPortalEntity.class, 
            parameters = {
                @StoredProcedureParameter(mode = ParameterMode.IN, type = Long.class)
            }
        )
    public List<AcompanhamentoCompraPortalEntity> listarComprasMicrosigaProc(@Param("idUsuarioAutenticado") Long idUsuarioAutenticado);

不编译。

我收到了这个错误:

注释@NamedStoredProcedureQuery 不允许用于此位置

我的导入(Java):



import java.util.List;
import java.util.Set;

import javax.persistence.NamedStoredProcedureQuery;
import javax.persistence.StoredProcedureParameter;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

【问题讨论】:

    标签: java sql jpa stored-procedures


    【解决方案1】:

    您必须在 class 级别添加 @NamedStoredProcedureQuery 注释及其详细信息,而不是在 field/attribute 级别:

    @Entity
    @NamedStoredProcedureQuery(
    // further specifications ...
    )
    public class MyEntity {
          // fields, getter/setter methods, etc.
    }
    

    纠正后,错误(消息)

    注释@NamedStoredProcedureQuery 不允许用于此位置

    应该消失。

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2011-02-25
      • 2015-06-19
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      • 2020-02-11
      • 2011-01-29
      相关资源
      最近更新 更多