簡體   English   中英

參數未在 Hibernate 查詢中綁定

[英]Parameter not bound in Hibernate Query

我嘗試使用 Spring 數據進行查詢以通過 id 更新條目,我嘗試了很多選項但我仍然無法擺脫這個:

Named parameter not bound : table.eventDate
@Modifying
@Query(value = "update Table_name u set u.id = :table.id, u.event_date = :table.eventDate, u.client_id = :table.clientId, u.status = :table.status, u.status_date = :table.statusDate, u.creation_date = :table.creationDate, u.last_update_date = :table.lastUpdateDate where u.id = :table.id",
    nativeQuery = true)
void updateEntity(@Param("table") Table table);


我應該如何編寫查詢才能擺脫這種情況?

我在網上嘗試了很多可能性來編寫查詢,但沒有任何效果。

正確的原生查詢語句:

@Modifying
@Query(value = "update Table_name u set u.id = :table.id, u.event_date = :table.event_date, u.client_id = :table.client_id, u.status = :table.status, u.status_date = :table.status_date, u.creation_date = :table.creation_date, u.last_update_date = :table.last_update_date where u.id = :table.id",
    nativeQuery = true)
void updateEntity(@Param("table") Table table);

由於您使用的是本機查詢而不是 JPQL 查詢,因此您必須編寫:table.event_date 而不是:table.eventDate。 相同的計數例如:table.clientId,它必須是:table.client_id。 希望它能奏效!

本機查詢:總是 snake_case 而不是 camelCase,除非你的列名是 camelCase,但我對此表示懷疑。 :)

暫無
暫無

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

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