我可以在 bean 验证中使用 Hibernate 实体注释吗 [英] Can I use hibernate entity annotations with bean validation
本文介绍了我可以在 bean 验证中使用 Hibernate 实体注释吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要在 JSF 2 中对表单字段使用 bean 验证,您可以在 bean 中使用注释,如 @Length(max=5)
.
To use bean validation for form fields in JSF 2, you can use annotations in the bean like @Length(max=5)
.
然而,由于这些约束已经在我的 Hibernate 实体对象中定义,例如:@Column(name = "FIELDX", length = 5)
,我想知道是否有办法使用他们进行验证?
However, since these constraints are already defined in my Hibernate entity object, for example: @Column(name = "FIELDX", length = 5)
, I was wondering if there's a way to use them for the validation?
推荐答案
不,你不能.你不应该,因为:
No, you can't. And you shouldn't, because:
- 在保留字段定义的同时验证逻辑可能会发生变化
- 只有少数约束可以映射到列定义
这篇关于我可以在 bean 验证中使用 Hibernate 实体注释吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文