hibernate-validator

With Hibernate validation, can I query the entity being validated?

帅比萌擦擦* 提交于 2019-12-22 09:42:45
问题 I have an entity on which I need to implement the following constraint: "There may only ever be one record for any combination of columns X and Y, for which column Z is null if the record is of type A." The last part turns this from a simple uniqueness constraint to something more complex. I'm writing a custom Hibernate validator to check it. What I'm doing is: @Override public boolean isValid(MyEntity value, ConstraintValidatorContext context) { Query query = DB.createQuery( // DB is just a

Annotation for hibernate validator for a date at least 24 hours in the future

爱⌒轻易说出口 提交于 2019-12-22 08:44:01
问题 I know that exist annotation @Future. If I annotate field with this annotation @Future private Date date; date must be in future means after current moment. Now I need to validate that date was at least 24 hours after current moment. How can I make it? 回答1: AfterTomorrow.java: @Target({ FIELD, METHOD, PARAMETER }) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = AfterTomorrowValidator.class) @Documented public @interface AfterTomorrow { String message() default "{AfterTomorrow

Disabling hibernate validation annotations dynamically at runtime?

本秂侑毒 提交于 2019-12-22 00:02:54
问题 Is it possible to turn off certain constraints / annotations per class at runtime? For instance if I wanted to turn of a @NotNull check on a firstName field, is that possible? This would make testing to see whether a certain constraint is triggered correctly simpler, as I could turn off all the other constraints, and just check that one constraint. 回答1: Is it possible to turn off certain constraints / annotations per class at runtime? For instance if I wanted to turn of a @NotNull check on a

Hibernate Validator - @Length - How to specify separate message for min and max?

旧城冷巷雨未停 提交于 2019-12-20 10:10:12
问题 I am using Hibernate validator for form validation in my web-app. I am using the @Length annotation for my String attribute as follows: @Length(min = 5, message = "The field must be at least 5 characters") private String myString; However, I have a need to display a different message if the String exceeds 50 characters. Is there a way to use the out-of-the-box @Length validator to do this? An example of what I would like to do (compiler will not let me) is as follows: @Length(min = 5, message

nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.ConfigurationImpl

江枫思渺然 提交于 2019-12-19 11:27:52
问题 public ModelAndView Details(@ModelAttribute("") @Validated App app, BindingResult result, @RequestParam(value="paramSessionAttr", required=false) String sessionAttr, @RequestParam("paramAction") @NotNull @NotEmpty String param_action){ ... } When I implement @NotNull @NotEmpty annotation validator in getParam its cause error said : org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appController' defined in file [C:\apache-tomcat-8.0.29\wtpwebapps

How to validate a List<BigDecimal> with @DecimalMin and @DecimalMax?

 ̄綄美尐妖づ 提交于 2019-12-19 11:05:54
问题 In my Spring project I have a POJO class with a property for a CMYK color. I want this property to be represented by a JSON array with exactly 4 floating-point numbers. Each number must be in the range between 0.0 and 1.0 . Currently I'm struggling with the validation of this property. I have researched already and found that the @DecimalMin and @DecimalMax annotations cannot be used on Float or float (see the answers to this question). Therefore I already abandoned List<Float> and use List

How to validate field level constraint before class level constraint?

人走茶凉 提交于 2019-12-19 04:15:15
问题 I have a class: @ColumnNameUnique(groups = CreateTableChecks.class) public class Table { @Valid @NotEmpty(groups = CreateTableChecks.class) private List<Measure> measures; } The class level constraint @ColumnNameUnique(groups = CreateTableChecks.class) always runs first, after that the field level constraint @NotEmpty(groups = CreateTableChecks.class) runs. Is there anyway to force the the field level constraint @NotEmpty(groups = CreateTableChecks.class) runs first? 回答1: You need to use

Internationalization in Hibernate validators

空扰寡人 提交于 2019-12-19 02:52:11
问题 Does Hibernate validators supports internationalization. I saw the jar and I could see the various ValidationMessages.properties file. Can we create our own custom error messages which will be internationalized? I don't want to use error messages provided by default in Hibernate validators. We need to use our own custom message and they should be internationalized. As well what are the languages supported by the Hibernate validators. In jar I saw properties files for the English, French,

Exception in hibernate-validator. nested exception is java.lang.NoClassDefFoundError: ConfigurationImpl

爷,独闯天下 提交于 2019-12-18 08:39:47
问题 Details: I am making form-validation using javax-validation and hibaernate-validator in Spring. Other than basic necessary JAR files for Spring. I have included: validation-api-1.1.0.Final hibernate-validator-5.1.0.Final I read somewhere that spl4j version is also in concern: so I'm also telling: ###slf4j-api-1.7.5### ###slf4j-simple-1.7.5### ###log4j-1.2.17### Can the cause of error be due to slf4j and log4j compatibility? I use annotation base validation. Let me provide some code: Customer

Spring Rest Controller: how to selectively switch off validation

时光怂恿深爱的人放手 提交于 2019-12-18 07:48:21
问题 In my controller I have a method for creating an entity import javax.validation.Valid; ... @RestController public class Controller { @RequestMapping(method = RequestMethod.POST) public ResponseEntity<?> create(@Valid @RequestBody RequestDTO requestDTO) { ... with import org.hibernate.validator.constraints.NotEmpty; ... public class RequestDTO @NotEmpty // (1) private String field1; //other fields, getters and setters. I want to add a controller method update(@Valid @RequestBody RequestDTO