简体   繁体   English

如何使用 JPA 注解 @NamedStoredProcedureQuery 执行存储过程

[英]How Execute Stored Procedure using JPA annotation @NamedStoredProcedureQuery

How convert this procedure execution using @NamedStoredProcedureQuery?如何使用@NamedStoredProcedureQuery 转换此过程执行?

I have this SQL, It's OK!我有这个SQL,没关系!

SQL (it's Works OK): SQL(工作正常):




USE [INTEGRADOR]
GO

DECLARE @return_value int

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

SELECT  'Return Value' = @return_value 

GO


In Java i Try this, but not working.在 Java 我试试这个,但不工作。 idUsuarioAutenticado is @CODIGO = 71648 idUsuarioAutenticado 是 @CODIGO = 71648


JAVA (Error when compile): 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);

Not compile.不编译。

I received this errors:我收到了这个错误:

The annotation @NamedStoredProcedureQuery is disallowed for this location此位置不允许使用注释 @NamedStoredProcedureQuery

My imports (Java):我的进口(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;

Instead of at field /attribute level, you have to add the @NamedStoredProcedureQuery annotation and its details at class level:而不是在字段/属性级别,您必须在class级别添加@NamedStoredProcedureQuery注释及其详细信息:

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

With that corrected, the error (message)更正后,错误(消息)

The annotation @NamedStoredProcedureQuery is disallowed for this location此位置不允许使用注释 @NamedStoredProcedureQuery

should disappear.应该消失。

Hope it helps.希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Spring 4 JPA Hibernate 5 中对 @NamedStoredProcedureQuery 的过程使用架构 - Using schema for Procedure on @NamedStoredProcedureQuery in Spring 4 JPA Hibernate 5 Spring JPA 中 NamedStoredProcedureQuery 中的错误 - “找到与位置参数关联的命名存储过程参数” - Error in NamedStoredProcedureQuery in Spring JPA - “Found named stored procedure parameter associated with positional parameters” 无法执行JPA的存储过程 - Can not execute stored procedure JPA @NamedStoredProcedureQuery 不适用于 JPA Java 中的简单过程调用 - @NamedStoredProcedureQuery is not working for the simple procedure call in JPA Java 如何使用JPA和Spring Data执行存储过程? - How can I execute a stored procedure with JPA & Spring Data? 如何通过Spring Boot使用JPA的crudrepository执行存储过程?[PropertyReferenceException] - How to execute a stored procedure with JPA's crudrepository with Spring boot?[PropertyReferenceException] 如何使用JAVA异步执行存储过程 - how to execute stored procedure asynchronously using JAVA 如何使用@Query Spring JPA批注执行查询 - How to execute a query using @Query Spring JPA annotation 如何使用mybatis调用oracle存储过程(基于注释)。 - How to call oracle stored procedure using mybatis (annotation based.) 如何使用JPA 2在存储过程中将复杂对象数组作为IN参数传递 - How to pass Array of complex objects as a IN parameter in a stored procedure using JPA 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM