[英]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);
得到錯誤:
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
您不能使用@Query
執行存儲過程
您必須在實體上定義NamedStoredProcedureQuery
@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 {}
然后你可以使用@Procedure
來執行它
@Procedure
Integer plus1inout(@Param("arg") Integer arg);
請閱讀文檔: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.stored-procedures
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.