【发布时间】:2022-01-15 01:17:43
【问题描述】:
我正在使用 Micronaut 框架,我有以下设置: 有一个名为 Transaction 的实体,有一个 Long 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 找到我想要更新的事务,并更新它的报告列。
【问题讨论】:
-
您是否尝试过使用
@Query编写自定义查询?这样,函数名称就无关紧要了,您可以将其命名为其他名称。 -
我试过了,这当然是一个选择。但如果可能的话,我想使用这种自动生成方法,并且我非常确信 updateReportByUuid 这个名称是正确的,我无法弄清楚它为什么无法构建。
-
另一个问题可能是,虽然 UUID 在技术上是唯一的,但在架构中的任何地方都没有显示,因此
batch updates的错误 -
我尝试在实体代码中添加一些约束,例如使用@Column(unique = true),但没有帮助。
标签: java spring hibernate micronaut micronaut-data