It's V E R Y worthwhile mentioning that putting hibernate validation annotations on entity beans will not always yield the outcome a new seam user would expect.
This is because if no value is provided in a form, then no validation will be applied by JSF at all. If at the same time a hibernate validation annotations are applied on the value, then you get an validaiton exception in the server.log.
However, this validation exception is not propagated to the user face and won't show up there. This can drive one crazy, if one does not know about this. The solution is to place a required="true" onto the JSF component, which will turn validation on.
I think this is something, which should be somehow resolved, because it's very confusing to a new seam user - at least it was for me.
In Short:
Placing @NotNUll, @Length, @Future and other hibernate annotations on fields of your entity bean, will only work smothely, if you also place a required="true" onto the UI JSF component, responsible for setting the value!
Much shorter;)
If you do not use a required="true" on an input field in charge of an entity bean property BUT a validation annotation on the the entity bean property like @NotNull or @Length you are heading for trouble.
Possible workaround:
If we need validation for not required field (for example email), we can do that:
@Entity MyEntity{ @Email private String email; @PrePersist @PreUpdate public void fixEmail(){ if (property != null && property.length() == 0) property = null; } ...
Comments