cejug/hurraa — pull request #69 by efraimgentil (2014-02-11 03:02:38+00:00)
Title: Uniqueness Bean Validation

* Addition of @Unique to handle uniqueness validation see example in EquipmentType model.

The annotation required 3 parameters,
1. propertyName , represents the property you want to verify uniqueness also needed to specify which field the error message will be linked.
2. identityPropertyName, represents the identity of the entity, is used to handle update actions
3. entityClass, Used to identify the entity that will be verified in the database, and to access the attributes with reflection.

The annotation can be placed in two places, in the type of the entity ( the class declaration ) , but it will trigger the validation two times, one for the @Valid annotation the second when it going to be persisted it will trigger again the validation.
Or you can place in the parameter that represent the type you want to validate in a controller method, it will trigger the validation only one time, but you have to put in all the methods that you want to make the validation.

The point that you need to annotate the type its because you need to access differents fields of the class like the id, to verify the uniqueness on a update action.

Open to discussion.