hibernate-validator

Spring 3.1 Autowiring does not work inside custom constraint validator

隐身守侯 提交于 2019-12-08 23:17:57
问题 I have an issue with bean autowiring inside a custom constraint validator. A constraint validator instance is not given using Spring's LocalValidatorFactoryBean. The JSR-303 provider is hibernate-validator 4.2.0.Final. Spring configuration excerpt : <!-- JSR 303 validation --> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /> <bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor"/> Custom Constraint

Hibernate Validator exception “No validator could be found for type: java.lang.String.”

核能气质少年 提交于 2019-12-08 17:26:14
问题 I use Spring and Spring MVC 3.1, Hibernate 3, Hibernate Validator 4.3. I want to add my custom constraint validator, but it seems that my validator not called and always got "No validator could be found for type" exception. Did I make any mistake? I got a big problem of getting this exception always javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.String. at org.hibernate.validator.internal.engine.ConstraintTree.verifyResolveWasUnique

Difference between @Max and @DecimalMax (and @Min and @DecimalMin)

假如想象 提交于 2019-12-08 16:10:09
问题 What's the difference between @Max and @DecimalMax , and @Min and @DecimalMin in Hibernate Validator? Looking at the Javadocs, they seem to be enforcing the same constraint. 回答1: If you take a look at the reference documentation, you'll see that the @Min & @Max annotations both have an impact on the Hibernate metadata while @DecimalMin & @DecimalMax don't. Namely, they add check constraints (which effectively improves your relational mapping). Also @Max & @Min accept a long value, while

Hibernate validator eats CPU on regex matching

廉价感情. 提交于 2019-12-08 10:00:35
问题 We are trying to validate address using hibernate validator. Some times hibernate validator hangs on java regex matching. It completed eats CPU usage and not able to process anything else. Is there any way to escape from this? Is this a bug in java 6?? java.lang.Thread.State: RUNNABLE at java.lang.Character.codePointAt(Character.java:2335) at java.util.regex.Pattern$CharProperty.match(Pattern.java:3344) at java.util.regex.Pattern$Curly.match(Pattern.java:3737) at java.util.regex.Pattern$Ques

Dropwizard validate a field only on @POST

≯℡__Kan透↙ 提交于 2019-12-08 08:23:19
问题 I have these read-only fields which needs to be secure, like passwords. Say we have a user object: public class User { @NotEmpty @Size(max = 100) private String name; @NotEmpty private String username; @NotEmpty @Email private String email; private String password; @JsonIgnore public String getPassword() { return password; } @JsonProperty public void setPassword(String password) { this.password = password; } } So, this works nicely; as in I can get/post/put whatever I want, but I will never

Hibernate Validator: Intercept Invalid Values

≯℡__Kan透↙ 提交于 2019-12-08 06:31:49
问题 I'd like to set up my beans to use both Hibernate Validator (for validation) and Google Guice (for DI and method interception). Ideally, I'd like to have a setup where any method that "fails" validation will cause a method interceptor to be called: public class Widget { @NotNull public Fizz getFizz() { return fizz; } } public class FailedWidgetInterceptor implements MethodInterceptor { public Object invoke(MethodInvocation invocation) throws Throwable { // This gets executed if Widget's

GWT 2.4: “An internal compiler exception occurred” in project that uses Hibernate for Bean Validation

故事扮演 提交于 2019-12-08 05:42:23
问题 It's been about 5 hrs since I decided to use JSR 303 Bean Validation in my GWT project and I gotta say I can't even express (politely) how deeply unsatisfied I am with lame documentation on the subject on Google's website. I really hope you guys can help me. I followed this blog post to add client-side bean validation to my project. Unfortunately it worked only once and threw an exception in runtime saying that I need to add Hibernate Validation sources to class path. I fixed that and decided

Custom Message Key in Hibernate validator not working with message.property

空扰寡人 提交于 2019-12-08 05:06:14
问题 I am working on Spring Boot, I have used Hibernate Validator to validate my beans. I have added a custom key with the @NotEmpty annotation, and add thos key/value pair in message.properties, but it's not getting its value from message.property Here is my bean with validation annotation: public class CategoryBean { @NotEmpty(message = "{category.name.notempty}") private String name; ----getter setter----- } message.properties (path:src/main/resources/message.properties) category.name.notempty

ConstraintViolationException: User Entity with transient confirmPassword field

梦想与她 提交于 2019-12-08 04:41:15
问题 I'm not able to submit my spring form. I'm getting this exception and don't know why: javax.validation.ConstraintViolationException: validation failed for classes [com.example.my.entities.User] during persist time for groups [javax.validation.groups.Default, ] And here's my User entity: @Entity @Table( name = "tbl_user" ) public class User implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue @Column( name = "id", nullable = false, columnDefinition =

HibernateValidator 5 seems to not cascade validation on JPA entities

巧了我就是萌 提交于 2019-12-08 04:22:00
问题 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