hibernate-validator

Purpose of @NotNull.List

情到浓时终转凉″ 提交于 2019-12-12 08:47:33
问题 When I looked among the standard constraints in Bean Validation API (JSR-303), I found the NotNull.List annotation. Its description is: Defines several @NotNull annotations on the same element This is valid syntax: @NotNull.List({@NotNull, @NotNull}) private Object myObject; But it makes no sense. Either the object is null or it is not. When would you use this annotation? There are several other similar annotations like AssertFalse.List and AssertTrue.List . 回答1: You can have multiple

Disable Hibernate validation for Merge/Update

筅森魡賤 提交于 2019-12-12 04:44:28
问题 I have a POJO called Order as follows: public class Order { @Id @GeneratedValue @Column(name="id") protected int id; @NotNull @Future protected Date desiredProcessingDate; protected Date actualProcessingDate; } As you can see, desiredProcessingDate must be specified and it must be in the future. A user will submit a new order through a form and specify a desiredProcessingDate , which is being validated as expected. The order is then persisted to the database via sessionFactory

JBoss will not start with Hibernate Validator

蹲街弑〆低调 提交于 2019-12-12 02:52:26
问题 I am trying to use Hibernate Validator. When attempting to start my JBoss I get the following: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.ConfigurationImpl My environment is: JBoss 5.2 Java 1.8 Spring 3.2.11 These are what

form:errors doesn't render on jsp

情到浓时终转凉″ 提交于 2019-12-12 01:27:54
问题 I have following controller: @RequestMapping(value = "/member/createCompany/addParams", method = RequestMethod.POST) public String setCompanyParams( @ModelAttribute MyDto myDto, @RequestParam(value = "g-recaptcha-response") String recapchaResponse, HttpSession session, Principal principal, Model model) throws Exception { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); Validator validator = factory.getValidator(); Set<ConstraintViolation<MyDto>> violations; if(condition1)

Bean Validation: Receive EntityNotFoundException though have a constraint to validate entity

跟風遠走 提交于 2019-12-11 19:19:23
问题 Technologies: Spring, Hibernate, JSR-303, JQuery Platform: Windows I am trying to implement @IdMustExist JSR-303 constraint. The purpose of the constraint is to check whether the entered id value exists in associated table. Please see this link for the IdMustExist.java and IdMustExistValidator.java code snippets. Scenario 1 - Valid Id value is entered: In this case, when hibernate's EntityManager.merge operation is executed, I see that the @IdMustExist constraint is executed. It successfully

addPropertyNode - equivalent in version 1.0?

泪湿孤枕 提交于 2019-12-11 18:59:08
问题 Relatively simple probably. The Java 7 documentation for the ConstraintViolationBuilder interface specifies: addNode ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(String name) Deprecated. since 1.1 - replaced by addPropertyNode(String) and addBeanNode() Adds a node to the path the ConstraintViolation will be associated to. name describes a single property. In particular, dot (.) is not allowed. "Now" the documentation also includes the methods

Hibernate validator validate empty field where is not @NotEmpty

久未见 提交于 2019-12-11 18:26:48
问题 I have problem with Hibernate Validator 4.3.1. The problem is, that the validator is validating fields with are empty and don't have @NotEmpty annotations. When person's web form gets submitted and address, phone, fax and webpage are not set, an validation error is thrown. I think that's wrong, because there is no @NotEmpty annotation. I want skip fields with don't have @NotEmpty annotation. Can anyone explain where the problem is? Thank you. public class Person{ private String name; private

Spring Message Interpolation Argument Replacement using Hibernate Validator

感情迁移 提交于 2019-12-11 16:21:40
问题 https://docs.jboss.org/hibernate/validator/5.0/reference/en-US/html/chapter-message-interpolation.html According to the hibernate validation documentation, the following can be done where {min} and {max} parameters are replaced in error message accordingly. @Size( min = 2, max = 14, message = "The license plate must be between {min} and {max} characters long" ) I am using this notation in a Spring application but these arguments are not replaced. I get back "The license plate must be between

hibernate validator LengthValidator of truncated string

て烟熏妆下的殇ゞ 提交于 2019-12-11 14:03:39
问题 Is there a similar annotation to @Length in hibernate validator but it restricted on a trimmed string. For example: I have @Length(max= 2); String str; when: str = " ab" ; --> it will pass ok. Thanks, 回答1: As fare i know, there isn't one. But you can easely implement your own. The other (not so good) way is to add a getter which trim the string. @Length(max= 2); String getTrimmedStr() { return this.str.trim(); } But i think implementing your own Validator is the much cleaner approach. 回答2: I

Short circuiting constraints on a field in hibernate validator

 ̄綄美尐妖づ 提交于 2019-12-11 11:16:15
问题 I want the constraints on fields of a class to be ordered and short-circuit, e.g. @Size(min = 2, max = 10, message = "Name length improper") @Pattern(regexp = "T.*", message = "Name doesn't start with T") private String name; with name="S" , should fail the @Size constraint and hence not even bother checking the next one. I went through Groups, GroupSequence and Composite Constraints but nothing seems to be of use. Specifically, GroupSequence will not work for my case. Consider this: public