hibernate-validator

Correct way to do an EntityManager query during Hibernate Validation

試著忘記壹切 提交于 2019-11-30 13:26:20
I'm a bit of a Java EE/EJB noob, but from the docs and other posts I've gathered you cannot query the database using the same entitymanager/session during entity validation. In general, the lifecycle method of a portable application should not invoke EntityManager or Query operations, access other entity instances, or modify relationships within the same persistence context.[43] A lifecycle callback method may modify the non-relationship state of the entity on which it is invoked. Translation please? This is pretty abstract...can it be explained in more concrete terms? It leads to more

Autowired gives Null value in Custom Constraint validator

情到浓时终转凉″ 提交于 2019-11-30 12:51:50
I am totally new to Spring and I have looked in to a few answers on SO for the asked problem. Here are the links: Spring 3.1 Autowiring does not work inside custom constraint validator Autowiring a service into a validator Autowired Repository is Null in Custom Constraint Validator I have a Spring project in which I want to use Hibernate Validator for an object validation. Based on what I read online and a few forums I tried to inject validator as follows: @Bean public Validator validator() { return new LocalValidatorFactoryBean().getValidator(); } But wherever I was using @Autowired Validator

Spring 3.1 Autowiring does not work inside custom constraint validator

让人想犯罪 __ 提交于 2019-11-30 07:07:24
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 Validator: import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext;

Autowiring a service into a validator

不羁岁月 提交于 2019-11-30 06:57:20
问题 This example is a bit contrived; I've simplified it to remove extraneous details and to focus on the problem I am having. I have a validator that looks like this: @Component public class UniqueUsernameValidator implements ConstraintValidator<UniqueUsername, String> { @Autowired UsernameService usernameService; @Override public void initialize(UniqueUsername uniqueUsername) { } @Override public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) { return

Validating double and float values using Hibernate Validator - bean validation

岁酱吖の 提交于 2019-11-30 06:56:09
I'm looking for a way to validate a java.lang.Double field in the Spring command bean for its maximum and minimum values (a value must lie between a given range of values) like, public final class WeightBean { @Max(groups={ValidationGroup.class}, value=Double.MAX_VALUE, message="some key or default message") @Min(groups={ValidationGroup.class}, value=1D, message="some key or default message") private Double txtWeight; //Getter and setter. public interface ValidationGroup{} } But both @Max and @Min cannot take a java.lang.Double value. Note that double and float are not supported due to

Using a custom ResourceBundle with Hibernate Validator

我们两清 提交于 2019-11-30 06:55:05
I'm trying to set up a custom message source for Hibernate Validator 4.1 through Spring 3.0. I've set up the necessary configuration: <!-- JSR-303 --> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="validationMessageSource" ref="messageSource"/> </bean> The translations are served from my message source, but it seems that the replacement tokens in the messages themselves are looked up in the message source, i.e. for a: my.message=the property {prop} is invalid there are calls to look up 'prop' in the messageSource. Going

Hibernate Validator and Jackson: Using the @JsonProperty value as the ConstraintViolation PropertyPath?

百般思念 提交于 2019-11-30 04:45:34
问题 Say I have a simple POJO like below annotated with Jackson 2.1 and Hibernate Validator 4.3.1 annotations: final public class Person { @JsonProperty("nm") @NotNull final public String name; public Person(String name) { this.name = name; } } And I send JSON like such to a web service: {"name": null} Hibernate when it reports the ConstraintViolation uses the class member identifier "name" instead of the JsonProperty annotation value. Does anyone know if it is possible to make the Hibernate

Correct way to do an EntityManager query during Hibernate Validation

半城伤御伤魂 提交于 2019-11-29 19:38:48
问题 I'm a bit of a Java EE/EJB noob, but from the docs and other posts I've gathered you cannot query the database using the same entitymanager/session during entity validation. In general, the lifecycle method of a portable application should not invoke EntityManager or Query operations, access other entity instances, or modify relationships within the same persistence context.[43] A lifecycle callback method may modify the non-relationship state of the entity on which it is invoked. Translation

Autowired gives Null value in Custom Constraint validator

戏子无情 提交于 2019-11-29 17:55:43
问题 I am totally new to Spring and I have looked in to a few answers on SO for the asked problem. Here are the links: Spring 3.1 Autowiring does not work inside custom constraint validator Autowiring a service into a validator Autowired Repository is Null in Custom Constraint Validator I have a Spring project in which I want to use Hibernate Validator for an object validation. Based on what I read online and a few forums I tried to inject validator as follows: @Bean public Validator validator() {

java.lang.NoSuchMethodException: userAuth.User.<init>()

泪湿孤枕 提交于 2019-11-29 15:55:10
问题 I have the class with validation: public class User { @Size(min=3, max=20, message="User name must be between 3 and 20 characters long") @Pattern(regexp="^[a-zA-Z0-9]+$", message="User name must be alphanumeric with no spaces") private String name; @Size(min=6, max=20, message="Password must be between 6 and 20 characters long") @Pattern(regexp="^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$", message="Password must contains at least one number") private String password; public User(String _name,