我正在使用 Micronaut 框架,并且我有以下設定:有一個名為 Transaction 的物體,帶有一個長 ID 和三個欄位,一個 UUID、一個字串報告和一個字串狀態:
@Entity
public class Transaction {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private UUID uuid;
private String report;
private String state;
}
在 CrudRepository 中,我定義了以下查詢:
int updateByUuid(UUID uuid, String state);
這正確地使用給定的新狀態更新了我的交易物體。現在我想寫一個不同的查詢:
int updateByUuid(UUID uuid, String report):
顯然這無法構建,因為簽名是相同的。我嘗試撰寫以下內容:
int updateReportByUuid(UUID uuid, String report);
或者:
int updateReportByUuid(String report, UUID uuid);
(所以改變周圍的引數)這也失敗了,錯誤資訊是
Projections are not supported on batch updates
和
No possible implementations found
它沒有失敗的唯一一次是當我將函式更改為以下內容時:
int updateReportByUuid(@Id Long id, String report);
但顯然這是不正確的(因為我指定了 ByUuid,并且作為第一個引數我給出了一個 Long id),而且也不是我想要的功能。我想要的是讓資料庫通過它的“UUID”找到我想要更新的交易,并更新它的“報告”列。
uj5u.com熱心網友回復:
這被視為批量更新的原因是,因為您正在更新非主鍵欄位上的記錄。
如上所述,該欄位uuid在技??術上是唯一的,您也將其宣告為唯一的,但它不是主鍵。因此 Micronaut Data 將其視為批量更新。
您至少有以下兩個選擇。
- 將
id欄位從轉換Long為UUID并洗掉欄位uuid。在這種情況下,您的主鍵是 UUID,您的更新方法將開始作業。 - 通過添加
@Query注釋來告訴 Micronaut Data 要做什么。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/379000.html
標籤:爪哇 春天 休眠 微型宇航员 micronaut-数据
