简体   繁体   English

参数未在 Hibernate 查询中绑定

[英]Parameter not bound in Hibernate Query

I tried to make a query withSpring data for updating an entry by id and I tried a lot options but still I can't get rid of this:我尝试使用 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);


How should I write the query in order to get rid of this?我应该如何编写查询才能摆脱这种情况?

I tried a lot of posibilities online to write the query but nothing worked.我在网上尝试了很多可能性来编写查询,但没有任何效果。

Correct native query statement:正确的原生查询语句:

@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);

Since you're using a native query instead of a JPQL-Query, you have to write:table.event_date instead of:table.eventDate.由于您使用的是本机查询而不是 JPQL 查询,因此您必须编写:table.event_date 而不是:table.eventDate。 Same counts for example:table.clientId, it has to be:table.client_id.相同的计数例如:table.clientId,它必须是:table.client_id。 Hope it'll work!希望它能奏效!

Native Queries: Always snake_case instead of camelCase, unless your column names are in camelCase, but I doubt that.本机查询:总是 snake_case 而不是 camelCase,除非你的列名是 camelCase,但我对此表示怀疑。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM