最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - When to call Hibernate Validate - Stack Overflow

programmeradmin0浏览0评论

Where should calls to validate a Java object be made; 1) at the end of the constructor, or 2) after the call to new X()? If made in the constructor, then is gets called not only for each new, but if there is a subclass of that object. Your thoughts would be helpful.

Where should calls to validate a Java object be made; 1) at the end of the constructor, or 2) after the call to new X()? If made in the constructor, then is gets called not only for each new, but if there is a subclass of that object. Your thoughts would be helpful.

Share Improve this question asked Feb 6 at 2:56 B. StackhouseB. Stackhouse 5777 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It completely depends on the use case and logic. I prefer to call it after new X() as object will have data after some setters are called.

X obj = new X();
obj.setName("xyz");
obj.setId(1);
validator.validate(obj);
发布评论

评论列表(0)

  1. 暂无评论