hibernate-validator

Conditionally prevent cascading validation

和自甴很熟 提交于 2019-12-11 09:45:16
问题 Given the classes: class Foo { @Size(max = 1) @Valid private List<Bar> bars; } class Bar { @NotBlank private String snafu; } How can validation be applied that prevents Bar.snafu being validated when the Size constraint on Foo.bars failed? I though that i can achieve that with group conversion and the definition of a group sequence. but i failed configuring it the way i want. Even though it looks like, defining fail-fast is not an option. 回答1: The following solves this issue: interface

Custom error messaging on Hibernate Validation

老子叫甜甜 提交于 2019-12-11 04:56:43
问题 I am trying to set up Hibernate Validation in my ecommerce site. I have an order object with multiple objects assigned. As the customer goes through the checkout, I want to be able to individually validate these objects - sometimes multiple objects with one form. For example, upon submitting the delivery form, the deliveryCharge and deliveryAddress should be validated. If this validation fails, the delivery form will be returned with a list of validation errors. I can validate the objects via

Turn off or disallow validation dynamically at run time when certain event occurs in Spring MVC using HibernateValidator

爱⌒轻易说出口 提交于 2019-12-11 02:18:34
问题 I'm using HibernateValidator to validate forms in JSP using Spring MVC 3.0.2. Earlier, I was using the Validator interface to validate forms where it was possible to disallow validation when certain event occurs. For the sake of demonstration, I have one form on a JSP page where there are only two text fields and a submit button. When those fields are filled with appropriate values and the submit button is clicked, validation is performed first and values are inserted into the database, if

Hibernate Validator: Violation Message Language

自古美人都是妖i 提交于 2019-12-11 01:46:21
问题 I have a test class where I am testing a domain model which is annotated with e.g. @NotNull In my test class I am first getting the validator private static Validator validator; @BeforeClass public static void setup() { validator = Validation.buildDefaultValidatorFactory().getValidator(); } Later I have a JUnit Test where I am testing the domain model (lets say a Person) Set<ConstraintViolation<Person>> violations = validator.validate( aPerson ); Lets say, I want to retrieve the first

Hibernate Validator 6.0.8 jars causing exception

懵懂的女人 提交于 2019-12-11 00:57:17
问题 I am following a tutorial on Spring MVC and after attempting to implement Hibernate validation, I'm now getting HTTP Status 500 - Servlet.init() for servlet dispatcher threw exception when running the application on the server. I took the 3 Hibernate jar dependencies out of the POM.xml and it served up the home page without any issue (I had to comment the Hibernate validation annotations in the Customer object class) but when I added them back in (annotations were still commented) I got the

When using @AssertTrue in methods, the method is invoked 4 times during validation (Bean Validation)

本秂侑毒 提交于 2019-12-10 17:52:35
问题 When using bean validation to validate the state of an object, the method annotated with @AssertTrue is called 4 times whenever the validation is invoked. It should only be called once per invocation. Hibernate-validator version: 5.1.3.Final Here is an example: For the following class Motorcycle: import javax.validation.constraints.AssertTrue; class Motorcycle{ private int fuel; private int tireDurability; @AssertTrue(message = "motorcycle.not.available.to.use") public boolean isAvailable(){

Hibernate -validator group sequence provider getDefaultSequenceProvider gets null as input

强颜欢笑 提交于 2019-12-10 17:45:20
问题 I am using the hibernate validator group sequence and want to execute the groups in a sequence based on business rules. But the input to the groupSequenceProvider for its getValidationGroups is always null, and hence custom sequence never gets added. My request object: @GroupSequenceProvider(BeanSequenceProvider.class) public class MyBean { @NotEmpty private String name; @NotNull private MyType type; @NotEmpty(groups = Special.class) private String lastName; // Getters and setters } Enum type

f:convertNumber on Double: ClassCastException

与世无争的帅哥 提交于 2019-12-10 00:37:56
问题 In JSF 2.3, I have an h:inputText to edit a Double value, which has in addition Bean-Validation constraints. The h:inputText has a f:convertNumber . When submitting the form, this leads to a ClassCastException (see below). So, it seems, that f:convertNumber produces a Long which then, could not be converted to Double to validate the @DecimalMin constraint, right? In JSF 2.2 this worked as expected, the problem occured after upgrading to JSF 2.3. Does anybody has any ideas what could be the

How to do the Hibernate validation on the nested list objects?

最后都变了- 提交于 2019-12-09 16:53:29
问题 I need to validate the objects which are stored in the list on my form bean object. Below is my form bean object. public class Role implements java.io.Serializable { // Fields private int roleId; @NotBlank private String roleName; private boolean active; @Valid private List<Module> modules; // getters anfd setters } and below is my object which is present in the list of my main form bean object public class Module implements Serializable { private int id; @NotBlank private String moduleName;

HibernateValidator 5 seems to not cascade validation on JPA entities

别说谁变了你拦得住时间么 提交于 2019-12-09 03:37:34
I have a problem with Hibernate and Hibernate Validator 5. I have some entity, let's say Group and another entity Person . They are related as follows: Group has two references to Person - contact person and manager. They are both one-to-one relationships with full cascade and orphan removal options. What I want is to validate the contact person and the manager while the group is being saved. The more, I want a different validation group to be used to validate contact person and manager. In order to do this, I placed @ConvertGroup(from = Default.class, to = ContactPersonValidation.class)