休眠 5.4.2 UnwrapValidatedValue 自动

hibernate 5.4.2 UnwrapValidatedValue automatic

我们从 HV 4.x 升级到 HV 5.4.2,现在我们的界面如下

@NotNull
List<AccountInfo> getMultiClientAccountBalances(@NotNull ClientContext clientContext, @NotNull Optional<AccountFilter> accountFilter);

我遇到错误:

javax.validation.UnexpectedTypeException: HV000186: The constraint of type 'javax.validation.constraints.NotNull' defined on 'getMultiClientAccountBalances.arg1' has multiple matching constraint validators which is due to an additional value handler of type 'org.hibernate.validator.internal.engine.valuehandling.OptionalValueUnwrapper'. It is unclear which value needs validating. Clarify configuration via @UnwrapValidatedValue.

我知道可以通过在字段中添加 @UnwrapValidatedValue 来解决这个问题,但这必须添加到每个方法中,这对我来说是一项繁重的工作。有没有更简单的解决方案(除了升级到HV6.x)

遗憾的是,我看不出如何在不破坏其他用例的情况下在 5.4 中更改此行为。

并且没有简单的方法来禁用可选值处理程序,因为它是无条件添加的。

所以我会说你有两个解决方案:

  1. 搜索并替换所有@Constraint可选添加UnwrapValidatedValue选项
  2. 或移至 HV 6,我们在其中完全重新设计了此功能,我认为它应该可以按您预期的那样工作。我知道你不想要这个答案,但它就是这样......

1. 的问题是我们从 HV 中删除了这个注释(它是实验性的)以支持 Bean Validation 中包含的标准功能,因此您必须在移动到 6 时删除它。

我不知道你的确切环境,但 HV 6 与以前的版本高度兼容,所以它可能工作得很好。请注意依赖项,因为我们将工件的 groupId 从 org.hibernate 更改为 org.hibernate.validator。另请注意,您需要将验证-api 从 1.1 更新到 2.0.

6 已经非常稳定,如果您有任何问题,我们会立即修复。