Validating domain objects hibernate part 5
As building such web application is definitively out of this post’s scope, the task will be left as homework for you, in case that you want to start pulling the reins of Hibernate Validator in the Web terrain.It’s possible, however, to set up different groups in the form of simple interfaces, and specify which constraints must be validated according to a particular lifecycle phase.For brevity’s sake, the above example uses the default group.Should its state be validated before being persisted or updated in a database, or when passed around to other layer(s)? Prior to Java EE 6, Java didn’t provide a standard way of validating the fields of a domain class by mean of a centralized mechanism. The Java Beans Validation specification makes it fairly easy to selectively validate class fields (and even entire classes) by using constraints declared with a few intuitive annotations.
At the time of this writing, JSR 303 has only two compliant implementations that you can pick up out there, Apache BVal and Hibernate Validator.
It’s possible, however, to get the same result by using a standard instances here and there, and validate the constrained classes in multiple places, even in the wrong ones!
Validating domain objects hibernate part 5 comments