bean-validation

kotlin data class + bean validation jsr 303

↘锁芯ラ 提交于 2019-11-28 17:26:39
问题 I'm trying to get Kotlin working with jsr 303 validation on a spring-data-rest project. Given the following data class declarartion : @Entity data class User( @Id @GeneratedValue(strategy = javax.persistence.GenerationType.AUTO) var id: Long? = null, @Size(min=5, max=15) val name: String ) The @Size annotation has no effect here, making me able to save a user with a name of 1 character. It works well when executing the very same example but in a Java class instead of Kotlin. This makes me

Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'

不问归期 提交于 2019-11-28 10:50:17
I would like to store birthdate so I chose date at MySQL, when I create my entities based in my database, it turns out like this: import java.util.Date; // ..code @NotNull(message="fill you birthdate") @Temporal(TemporalType.DATE) private Date birthdate; But when I try to persist it gives me this error: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'. Please refer to embedded ConstraintViolations for details. What am I doing wrong here ? I was reading something about define time zone in Google, I'm from Brazil, how should I do

Inject Service in ConstraintValidator [Bean Validator - JSR 303] Spring

点点圈 提交于 2019-11-28 09:49:56
Good Afternoon, I am having problem to inject a service within a Bean Validator (JSR 303). I would be performing a validation, but I need to validate this record in my database; When I use my service it throws NullPointerException; Exception: Exception in thread "main" javax.validation.ValidationException: HV000028: Unexpected exception during isValid call. at org.hibernate.validator.internal.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:294) at org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:164) at org.hibernate.validator

Bean Validation and error messages at .properties file

自作多情 提交于 2019-11-28 09:31:13
i am working on a JSF Projekt with Glassfish. My validation works well but i dont become a custom error message. //Class = User, package = devteam @NotEmpty @Pattern(".+@.+\\.[a-z]+") private String emailAddress; My ValidationMessages.properties is in the WEB-INF folder with this content: devteam.User.emailAddress=Invalid e-mail address Thank you. Hardy You are having two problems here. First, the location of the ValidationMessages.properties file. It has to be in the root of the classpath, so move it into WEB-INF/classes Your second problems are the message keys. The default message key for

Good patterns for unit testing form beans that have annotation-based validation in Spring MVC

走远了吗. 提交于 2019-11-28 07:14:55
问题 When using annotation based validation for a form bean, what is the best practice for unit-testing those beans in order to ensure that correct validations annotations are specified for each field? For example, if you have: public class MyForm { @NotNull private String name; } What is the best way to verify that @NotNull is applied to it? One obvious way is to create a validator, throw a null at it and expect it to fail. But in my view this is not the best way as you'll be testing the

How do I get Spring MVC to invoke validation in a JUnit test?

蹲街弑〆低调 提交于 2019-11-28 07:00:54
I have a POJO called Browser that I've annotated with Hibernate Validator annotations. import org.hibernate.validator.constraints.NotEmpty; public class Browser { @NotEmpty private String userAgent; @NotEmpty private String browserName; ... } I've written the following unit test that tries to verify my Controller method catches validation errors. @Test public void testInvalidData() throws Exception { Browser browser = new Browser("opera", null); MockHttpServletRequest request = new MockHttpServletRequest(); BindingResult errors = new DataBinder(browser).getBindingResult(); // controller is

Hibernate - Error activating Bean Validation integration

不问归期 提交于 2019-11-28 01:56:22
I am trying to set up Hibernate. But when i try to create my Session Factory, with this code: Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); I get the error: org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:156) at org.hibernate

How can I disable javax.validation.api in JBoss 6.4

自闭症网瘾萝莉.ら 提交于 2019-11-28 01:26:52
Similar questions: How to use bean validation 1.1 in JBoss EAP 6.4.0? How to change bean-validation version on jboss EAP 6.3? Can you use bean validation 1.1 (JSR 349) in JBoss EAP 6.4.4? There seems to be some uncertainty if we can use Bean Validation 1.1 in JBoss 6.x. My current jboss-deployment-structure.xml: <?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"> <deployment> <dependencies> <!-- list of modules taken from https://access.redhat.com/articles/1122333 --> <module name="javax.activation.api" /> <module name="javax

JSR-303 bean validation with Spring does not kick in

我的梦境 提交于 2019-11-28 01:15:04
问题 I've configured a JSR-303 custom validator following what's given in the docs (http://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/html/validation.html), complete with LocalValidatorFactoryBean and Hibernate validator on the classpath. However, my validator just refuses to kick in. I've put up a dirt simple test project here (https://github.com/abhijitsarkar/java/tree/master/spring-jsr-303), along with a failing unit test. Should you decide to take a look, just clone it and run

Using Java EE 6 Bean Validation

丶灬走出姿态 提交于 2019-11-28 00:30:53
I am trying to use Java EE 6 Validation as specified here http://docs.oracle.com/javaee/6/tutorial/doc/gircz.html I have annotated a simple field @Max(11) @Min(3) private int numAllowed; The docs says "For a built-in constraint, a default implementation is available" but how do I specify this. My constraints checks are not kicking in. I would expect it to work on calling of the setter method for the field. The only import in my class is import javax.validation.constraints.Max; import javax.validation.constraints.Min; How/where do I specify the implementation? I am putting the constraint on a