[英]how to pass parameters to a stored procedure using @NamedNativeQuery in spring hibernate
我有一個帶有參數@id的過程,我也在Spring休眠狀態下調用@NamedNativeQuery,我想知道如何在@NamedNativeQuery的query屬性中的過程中傳遞參數
我的代碼看起來像這樣。
@NamedNativeQuery(name =“ Callmyprocedure”,query =“ {CALL sampleprocedure:id}”,callable = true,resultClass = Subscriber.class)
id是我的過程參數,但不起作用。
看這個:
@Entity
@NamedNativeQuery(name = "SampleNameQuery",query = "call spS_NamedQuery(?,?)",resultSetMapping="mapping",resultClass = NamedQuery.class)
@SqlResultSetMapping(name="mapping",columns=@ColumnResult(name="value"))
public class NamedQuery {
@Id
public String name;
@Column
public String value;
}
. . . .
然后您傳遞如下參數:
Transaction trx = null;
Session session = HibernateSessionFactory.getSession();
try {
trx = session.beginTransaction();
org.hibernate.Query query = session.getNamedQuery("SampleNameQuery");
query.setParameter(0,"fsdfsdf");
String value = "";
query.setParameter(1,value);
List objList = query.list();
trx.commit();
希望對您有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.