cejug / hurraa

Opensource project to resource management
GNU General Public License v2.0
16 stars 18 forks source link

Uniqueness Bean Validation #69

Closed efraimgentil closed 10 years ago

efraimgentil commented 10 years ago

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.