hibernate-validator

Can Hibernate Validator be used as component outside Hibernate?

I am trying to add validation for message payload (which are json). I am using Jackson Json processor for data binding, which works quite well for me, using bean methods and occasional annotation or two. But beyond data binding, I would like to declaratively validate actual values: and specifically I prefer annotations over any externa...

How can I change annotations/Hibernate validation rules at runtime?

If have a Java class with some fields I want to validate using Hibernate Validator. Now I want my users to be able to configure at runtime which validations take place. For example: public class MyPojo { ... @NotEmpty String void getMyField() { ... } ... } Let's say I want to remove the NotEmpty check o...

Why does Hibernate Validator @NotEmpty produce duplicate messages?

While working with Hibernate Validator, I noticed that the @NotEmpty and @NotNull annotations produce duplicate messages in the InvalidValue array returned by getInvalidValues(...). If I specify a message like @NotEmpty(message = "My error message."), then I'll get one InvalidValue of "My error message." and a second of "may not be null...

Display custom conversation error message with <rich:beanValidator />

I'm using hibernate validators with JSF. How can i set my conversation error messages. I'am trying such way, but it didn't work: <h:inputText id="input" value="#{myBean.number}" converterMessage="#{msgs.convertError}"> <f:convertNumber /> <rich:beanValidato...

Spring JSR303 validation doesn't work like described in Spring Documentation

I tried implementing validation for my web application like described in section 5.7.4.3 of the Spring 3.0 documentation: <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="webBindingInitializer"> <bean class="org.springframework.web.bind.support.ConfigurableWebBindin...

Hibernate-validator: @NotEmpty does not work for null values

Hi all. I have annotated a String field with @NotEmpty tag. When I try to persist the entity with this filed's value "", it works fine. Mechanism detects the validation error and raises an InvalidStateException exception notifying the issue. But when I try to persist the entity with this field's value null, an UndeclaredThrowableExcep...

Hibernate Validator Exceptions

I'm using Hibernate Validator in an application with EJB and Spring MVC. I'm using JBoss 5, Hibernate 3 and Spring MVC version 3. I'd like to try and catch validation exceptions at Spring Exception Resolver level and generate an error message based on the InvalidStateException message. I don't want to put exception handling logic in t...

How to user Hibernate @Valid constraint with Spring 3.x?

I am working on simple form to validate fields like this one. public class Contact { @NotNull @Max(64) @Size(max=64) private String name; @NotNull @Email @Size(min=4) private String mail; @NotNull @Size(max=300) private String text; } I provide getter and setters hibernate dependencies ...

@Range based hibernate validation checks

I would like to perform @Range based hibernate validation checks (org.hibernate.validator.RangeValidator) in my JPA entity code. But it seems to modify the generated SQL with this checks which I would like to avoid. (i.e In the range check, I have the current year as the @Range max value which is bound to change every year). Hence, I ha...

Cross field validation with Hibernate Validator (JSR 303)

Is there an implementation of (or third-party implementation for) cross field validation in Hibernate Validator 4.x? If not, what is the cleanest way to implement a cross field validator? As an example, how can you use the API to validate two bean properties are equal (such as validating a password field matches the password verify fiel...

Cross field validation with Hibernate Validator (3.1.0.GA)

How do we enforce cross field validation with hibernate validator 3.1.0.GA create table user (id, start_date, end_date, ...) e.g. college graduation finishing date for a student should be greater than the graduation start date How do we enforce this, so that the validation messages can be shown in the UI on save / update operations. T...

Hibernate validator NotEmpty trim issue

It appears that the Hibernate NotEmpty annotation does not result in an error for strings filled with whitespace (" "). Only works for nulls or empty strings (ie: new String()). Is there a workaround/fix for this? ...

Java generics question - Class<T> vs. T?

I'm using Hibernate validator and trying to create a little util class: public class DataRecordValidator<T> { public void validate(Class<T> clazz, T validateMe) { ClassValidator<T> validator = new ClassValidator<T>(clazz); InvalidValue[] errors = validator.getInvalidValues(validateMe); [...] } } Questio...

Hibernate validator issues tracking

The Hibernate validator issues tracker appears to indicate that a particular issue I am facing is fixed - but I am still suffering from this issue and we're on the latest version (4.0.2). The change history and summary seem to indicate this was fixed in 3.2.0 but then on the other hand the issue status is listed as "open".. Can anyon...

How to check for a length of 5 or 9 with hibernate validator?

I can validate the length of a String with an annotation like: @Length(max = 255) But what if I want to verifiy that the length is either 5 or 9? Can this be done with an annotation? ...

Spring MVC 3 Validation - Unable to find a default provider

I get an error when trying to set up Spring MVC validation. javax.validation.ValidationException: Unable to find a default provider I read in the documents that the default provider they use is the hibernate-validator. Do I need to include this library to get validation to work? Is it okay to include this library even though i'm not...

Override of an hibernate validator annotation ?

Hello, I would like to override a constraint in hibernate validator. Here is my base class: @Entity @Table(name = "Value") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "valueType", discriminatorType = DiscriminatorType.STRING) public abstract class Value extends CommonTable { private String ...

JSf 2 with Hibernate Validator 4 and Tomcat 6

Hi all, The problem I'm having is that my Bean Validation isn't working as I would expect. I have a Session Scoped Managed Bean with a name field that is bound to an h:inputText. The name must be entered, and have a minimum length of 1 character, and a maximum length of 5 characters. I expect that when I enter the name into the textbox...

Hibernate Validator - Using properties in the constraints xml

Hi, I have just started using hibernate validator. I am creating the constraints in an XML file(not annotations). The only problem I am having is that I would like to use properties inside the constraints. For example: <bean class="MyBean" > <constraint annotation="javax.validation.constraints.Min"> <element name=...

Generating a error code per property in Hibernate Validator

I am looking at using Hibernate Validator for a requirement of mine. I want to validate a JavaBean where properties may have multiple validation checks. For example: class MyValidationBean { @NotNull @Length( min = 5, max = 10 ) private String myProperty; } But if this property fails validation I want a specific error code t...