![](/img/trans.png)
[英]How to pass a list of objects to a stored procedure in oracle using hibernate native sql query
[英]How to pass a parameters in native query for stored procedure
我正在嘗試在本機查詢中傳遞存儲過程的參數,URL為http:// localhost:3025 / bbr?BatteryBankID = 1&fromDate = 2017-01-10&toDate = 2017-12-25
存儲過程
Alter PROCEDURE [dbo].[Sample]
@BatteryBankID Int,
@fromDate DateTime,
@toDate DateTime
AS BEGIN
select
bbr.StrVoltage,bbr.ChrgCurr
from BatteryBankReadings bbr
where bbr.BatteryBankID = @BatteryBankID
and ReadTime between @fromDate and @toDate
END
GO
倉庫
public interface SampleRepo extends CrudRepository<BatteryBankReadings, Integer> {
@Query(value = "{call Sample :BatteryBankID, ':fromDate', ':toDate'}", nativeQuery = true)
public List<BatteryBankReadings> samp(@Param("BatteryBankID") int BatteryBankID, @Param("fromDate") String fromDate,@Param("toDate") String toDate);
}
例外:
java.lang.IllegalArgumentException: Parameter with that name [fromDate] did not exist
at org.hibernate.jpa.spi.BaseQueryImpl.findParameterRegistration(BaseQueryImpl.java:487) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.spi.BaseQueryImpl.setParameter(BaseQueryImpl.java:638) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:163) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:32) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:139) ~[spring-data-jpa-1.11.9.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.StringQueryParameterBinder.bind(StringQueryParameterBinder.java:61) ~[spring-data-jpa-1.11.9.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:101) ~[spring-data-jpa-1.11.9.RELEASE.jar:na]
...........SO ON
請幫助我,在此先感謝-:)
通過將參數保持在括號內有效,
public interface SampleRepo extends CrudRepository<BatteryBankReadings, Integer> {
@Query(value = "{call Sample (:BatteryBankID, :fromDate, :toDate)}", nativeQuery = true)
public List<BatteryBankReadings> samp(@Param("BatteryBankID") int BatteryBankID, @Param("fromDate") String fromDate,@Param("toDate") String toDate);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.