[英]Duplication of concerns javax.validation.constraints and javax.persistence.Column
I would like to do some Bean validation of my entities so I can appropriately map the errors to send back to the client. 我想对我的实体进行一些Bean验证,以便可以适当地映射错误以将其发送回客户端。
I understand that the javax.validation.constraints annotations are used to achieve this. 我知道javax.validation.constraints批注用于实现此目的。 My issue is that for my schema generation I need to use the javax.persistence.Column annotation, to describe rules for the persistence layer.
我的问题是,对于我的模式生成,我需要使用javax.persistence.Column批注来描述持久层的规则。 This seems like I am duplicating my logic a little bit.
似乎我在重复一点逻辑。
@Size( max= Entities.SCHEMA_DESCRIPTION_LENGTH)
@NotNull
@Column(name = "Description", length = Entities.SCHEMA_DESCRIPTION_LENGTH)
private String description;
As you can see I have to specify that the column is 'Not Nullable for both validation purposes and schema generation purposes (same for column length). 如您所见,我必须指定该列“对于验证目的和架构生成目的都是不可为空的(与列长相同)。 This seems redundant.
这似乎是多余的。 Surely there is a way to kill two birds with one stone in this case, as it seems like it would be pretty common, if not standard.
在这种情况下,肯定有一种方法可以用一块石头杀死两只鸟,因为如果不是标准的话,这似乎很常见。
Thanks 谢谢
不幸的是,尽管验证和模式生成有时可能会重叠(例如,列长度和可空性),但是它们之间没有交互,因此您必须分别声明这两个问题(并重复自己)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.