简体   繁体   中英

passing multiple @params to stored procedure in JPA

@Query(value = "DECLARE @StartDateTime DATETIME = DATEADD(hour,-1,GETUTCDATE()) EXEC [Fetch].[mevisio_downtimedata] " +
            "@StartDateTime = :startDateTime," +
            "@workCenterList = :workCenterList",nativeQuery = true)
    List<DownTimeData> retriveOneHrDowntime(@Param("startDateTime") LocalDateTime startDateTime, @Param("workCenterList") List<String> workCenterList);

Getting Error:

2021-05-06 00:26:04.506 ERROR 14840 --- [   scheduling-1]    o.h.engine.jdbc.spi.SqlExceptionHelper   : Incorrect syntax near '('.
2021-05-06 00:26:04.513 ERROR 14840 --- [   scheduling-1]    o.s.s.s.TaskUtils$LoggingErrorHandler    : Unexpected error occurred in scheduled task    
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is
org.hibernate.exception.SQLGrammarException: could not extract ResultSet

You cannot execute stored procedures with a @Query

You have to define a NamedStoredProcedureQuery on an entity

@Entity
@NamedStoredProcedureQuery(name = "User.plus1", procedureName = "plus1inout", parameters = {
  @StoredProcedureParameter(mode = ParameterMode.IN, name = "arg", type = Integer.class),
  @StoredProcedureParameter(mode = ParameterMode.OUT, name = "res", type = Integer.class) })
public class User {}

And then you can use @Procedure to execute it

@Procedure
Integer plus1inout(@Param("arg") Integer arg);

Please read the documentation: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.stored-procedures

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM