簡體   English   中英

休眠異常-找不到命名參數[:laboratoryId]

[英]Hibernate Exception - could not locate named parameter [:laboratoryId]

我在Hibernate中有以下查詢。我收到了Hibernate Exception,但我不明白為什么Hibernate拋出此異常。 有人可以幫我嗎?

Session session = this.sessionFactory.openSession();

session.createQuery("delete from Laboratory l where l.id=:laboratoryId")
        .setParameter("laboratoryId", laboratoryId).executeUpdate();
session.close();

嘗試在=符號和綁定名稱:laboratoryId之間添加一些空格,並刪除別名:

Session session = this.sessionFactory.openSession();

session.createQuery("delete from Laboratory where id = :laboratoryId")
    .setParameter("laboratoryId", laboratoryId)
    .executeUpdate();
session.close();

您確定laboratorID有價值嗎? 對於我的查詢生成器,我使用了以下內容:

if (!laboratoryId.isEmpty()) { 
        query.setParameter("laboratoryId", laboratoryId());
        }

也可以查詢

  "delete o from Laboratory o"

if(!laboratoryId.isEmpty()){
query.append("where o.id = (:laboratoryId)")

}

但是我將其用於字符串值

請顯示laboratoryId的代碼-是用戶輸入還是什么?

你可以試試這個。

刪除條款

DELETE子句可用於刪除一個或多個對象。 以下是使用DELETE子句的簡單語法:

String hql = "DELETE FROM Employee "  + 
         "WHERE id = :employee_id";
Query query = session.createQuery(hql);
query.setParameter("employee_id", 10);
int result = query.executeUpdate();
System.out.println("Rows affected: " + result);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM