hibernate-validator

@GroupSequenceProvider and group is a superset

只谈情不闲聊 提交于 2019-12-25 02:42:34
问题 Simple class Person.class class Person { @NotNull(groups = {PartlyCheck.class}) private String name; @NotNull(groups = {FullCheck.class}) private String adress; private boolean isFullCheck; } Check interfaces public interface PartlyCheck{} public interface FullCheck extends PartlyCheck{} I use two approach: if(person.isFullCheck) { validator.validate(person, FullCheck.class); else { validator.validate(person, PartlyCheck.class); } 1. If isFullCheck=true used both checks (FullCheck.class and

NoSuchMethodError javax.validation.Validator.forExecutables() but the Junit works

岁酱吖の 提交于 2019-12-24 20:16:06
问题 Why do I get this exception NoSuchMethodError javax.validation.Validator.forExecutables() when I run the application and the following method is called but the exception is never thrown if I call the method from a JUnit test, it executes perfectly. I'm using Spring AOP 3.2.4 + AspectJ and Hibernate Validator 5.0.1. It complains that it can't find the forExecutables method. Thanks @Before("execution(* com.sadc.missioncontrol.api.client.models.workRequest.MaintainTimesheet.getPublicHolidays(..)

Why Spring Message Interpolation Argument Replacement using Hibernate Validator don't work?

可紊 提交于 2019-12-24 10:44:41
问题 I used Spring4 + Hibernate5 Validator to do the validation. I don't want use the default ValidateMessage.properties, so I define my own message properties under the I18N directory in the classpath root directory, the config information is below: <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames" value="I18N.messages,I18N.validation.ValidationMessages" /> <property name="defaultEncoding" value="UTF-8" /> <!-- Set whether

Java bean validation: Enforce a @Pattern only when the property is not blank

做~自己de王妃 提交于 2019-12-23 18:43:07
问题 I have a form that allows the user to optionally enter their zip code. I know how to validate the format of the zip code, by using a @Pattern constraint and regex. But as this is an optional field, I do not want the format validated if it is blank. How can I tell the system to ignore the @Pattern constraint if the field is blank? This is an optional field and I only want to validate it if it is not blank. public class MyForm { String firstName; String lastName; @Pattern(regex = "^\d{5}(?:[-\s

Stop Hibernate from creating not-null constraints

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 12:18:34
问题 Is there a way to stop Hibernate from creating not-null constraints for properties annotated with @javax.validation.constraints.NotNull when using hbm2ddl = create ? 回答1: From the documentation of Hibernate Validator: 6.1. Database schema-level validation Out of the box, Hibernate Annotations (as of Hibernate 3.5.x) will translate the constraints you have defined for your entities into mapping metadata. For example, if a property of your entity is annotated @NotNull , its columns will be

Inject Repository inside ConstraintValidator with Spring 4 and message interpolation configuration

我的梦境 提交于 2019-12-23 07:38:11
问题 I created a small example project to show two problems I'm experiencing in the configuration of Spring Boot validation and its integration with Hibernate. I already tried other replies I found about the topic but unfortunately they didn't work for me or that asked to disable Hibernate validation. I want use a custom Validator implementing ConstraintValidator<ValidUser, User> and inject in it my UserRepository . At the same time I want to keep the default behaviour of Hibernate that checks for

How can I programmatically call the same validator that runs on a @RequestMethod method with a @Valid parameter in Spring?

烂漫一生 提交于 2019-12-23 07:00:37
问题 I have a class with hibernate's validation annotation on some fields (such as @NotNull and @Size(min = 4, max = 50) , etc...) public class MyClass { Long id; @NotEmpty @Size(min = 4, max = 50) String machineName; @NotEmpty @Size(min = 4, max = 50) String humanName; // Getters, setters, etc… } I also have a custom controller that acts as a JSON API, and a JSON deserializer that creates MyClass objects when API methods are called. In my custom controller I have a method to create a new object

Bean Validation Group inheritance isn't working with Group Sequence Provider

六眼飞鱼酱① 提交于 2019-12-23 05:23:26
问题 I'm currently working on implementing an application that stores contact information which contains both foreign and domestic addresses, but the addresses can also be disabled. I have attempted to define three validation groups: a super group for the always validated info and two child classes for the different address states. public interface ContactValidation {} public interface DomesticValidation extends ContactValidation {} public interface ForeignValidation extends ContactValidation {} I

How to Enable Spring Validation

寵の児 提交于 2019-12-23 03:45:07
问题 After putting hibernate-validator.jar and javax.validation-api.jar in my classpath the my old validation turned off and org.springframework.dao.DataIntegrityViolationException is replaced by org.hibernate.exception.ConstraintViolationException which wraps SQL exception that is coming from table constraints and this is causing a lot of issues. It automatically turned JSR-303 validation on so it doesn't validate anything anymore. I have to put this two jars to be able to upgrade Jersey to 2.4,

Unit testing JSR-303 validation in Spring

廉价感情. 提交于 2019-12-22 10:06:24
问题 I am trying to add a unit test for an annotated bean in spring using JSR-303 validation. The bean is a simple one like this: public class Bean { @Size(max=XX) String text; } In the Spring config I have the all the necessary JAR-files: validation-api hibernate-validator The validator is initialized with: <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /> My attempt at a testcase looks like this (the spring and other fluff removed):