bean-validation

Unexpected UnsupportedOperationException on Hibernate validation failure

痞子三分冷 提交于 2019-11-28 00:26:44
Why am I getting an UnsupportedOperationException from Hibernate upon validation failure? I'm hoping for a ConstraintViolationException. Below is my DAO. When it passes validation it works fine. I'm using Hibernate and Hibernate Validator 4. I'm using Websphere 8.0. I think WebSphereExtendedJtaPlatform is the culprit, but I have no idea why. If I look at what's supposedly the source code for WebSphereExtendedJtaPlatform (follow link for the source) it looks like most of the methods there just throw UnsupportedOperationException. http://grepcode.com/file/repo1.maven.org/maven2/org.hibernate

Spring Boot JSR303 message code in annotation getting ignored

自作多情 提交于 2019-11-28 00:19:15
问题 In my Spring Boot app I have a backing bean where I am using JSR303 validation. In the annotation, I have specified the message code: @NotBlank(message = "{firstname.isnull}") private String firstname; Then in my message.properties I have specified: firstname.isnull = Firstname cannot be empty or blank My JavaConfig for the messageSource is: @Bean(name = "messageSource") public MessageSource messageSource() { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();

Custom Class Level Constraint for Crossfield validation not called

半城伤御伤魂 提交于 2019-11-27 23:56:38
I am trying to implement a crossfield validation (JSR-303) with a custom annotation on class level. However the isValid method is not called (but the initialize method). So my question is: Why is the isValid method not being called for this class level validator? Defining it on property level works! I tried it on JBoss AS 7 and Websphere AS 8. Here is the code and a JUnit test (which works) Test.java public class Test { @org.junit.Test public void test() throws ParseException { Person person = new Person(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMDD"); person.setPartyClosingDateFrom

can I override a jsr-303 validation annotation

做~自己de王妃 提交于 2019-11-27 23:06:00
I have a test like below: public class TestSizeAnnotation { public static void main(String[] args) { System.out.println( Validation.buildDefaultValidatorFactory().getValidator().validate(new C())); } public static class P { private List<String> lst = newArrayList("AA"); @Size(max=0, message="P") public List<String> getLst() { return lst; } public void setLst(List<String> lst) { this.lst = lst; } } public static class C extends P { @Override @Size(max=5, message="C") public List<String> getLst() { return super.getLst(); } } } with the following output: [ConstraintViolationImpl

JSR303 custom validators being called twice

半腔热情 提交于 2019-11-27 22:26:12
I am creating a website using Spring MVC and for persistence I am using Spring Data JPA with Hibernate 4 as my JPA provider. Validation is being handled at present with Hibernate Validator. I have a problem whereby my validators are being called twice and I can't figure out why. The main reason this is a problem is because the second time round, dependencies are not being autowired into the validator and I am getting a null pointer exception. The following is the sequence of calls leading up to the failure: The registration form is submitted and first the NotDefaultSectValidator is called and

Why can't I use Valid parameter along with RequestParam in Spring MVC?

回眸只為那壹抹淺笑 提交于 2019-11-27 22:16:31
问题 Example: public String getStudentResult(@RequestParam(value = "regNo", required = true) String regNo, ModelMap model){ How can I use @valid for the regNo parameter here? 回答1: Late answer. I encounter this problem recently and find a solution. You can do it as follows, Firstly register a bean of MethodValidationPostProcessor : @Bean public MethodValidationPostProcessor methodValidationPostProcessor() { return new MethodValidationPostProcessor(); } and then add the @Validated to the type level

javax.servlet.ServletException: HV000030: No validator could be found for type: java.lang.Integer

我怕爱的太早我们不能终老 提交于 2019-11-27 20:03:49
I have to update information in my database. FacadePatient.java class code: public Patient update(Patient p) { Patient pat = em.find(Patient.class, p.getPatientId()); p.setPatientPhone(pat.getPatientPhone()); p.setPatientDateNaiss(pat.getPatientDateNaiss()); p.setPatientEmail(pat.getPatientEmail()); p.setPatientJob(pat.getPatientJob()); p.setPatientSmoking(pat.getPatientSmoking()); p.setPatientSize(pat.getPatientSize()); em.merge(pat); return p; } HV000030: No validator could be found for type: java.lang.Integer That will happen when you use JSR303 bean validation in flavor of Hibernate

JSR-303 Type Checking Before Binding

旧城冷巷雨未停 提交于 2019-11-27 19:52:53
model.... @Digits(integer=5, fraction=0, message="The value must be numeric and less than five digits") private int value; beans file.... <mvc:annotation-driven /> controller.... @RequestMapping(value = "/admin/save.htm", method = { RequestMethod.POST }) public ModelAndView saveSection(@Valid @ModelAttribute Section section, BindingResult result) { if(result.hasErrors()) { return new ModelAndView("admin/editSection", "section", section); } How do I restrict "value" to just numerics? If I enter something other than a number, I get this error: Failed to convert property value of type java.lang

Java Bean Validation (JSR303) constraints involving relationship between several bean properties

自古美人都是妖i 提交于 2019-11-27 19:24:56
Say I have the following simple java bean: class MyBean { private Date startDate; private Date endDate; //setter, getters etc... } Is there a mechanism in JSR 303 to create a custom validator that validates the constraint that startDate must be before endDate? It seems to me to be a common use case, yet I cannot find any examples of this kind of multiple property relationsship constraint. I can think of a few things to try. You could create a Constraint with a target of the type itself with an appropriate validator: @ValidateDateRange(start="startDate", end="endDate") public class MyBean { You

how to create a ConstraintValidator for List

孤人 提交于 2019-11-27 18:46:52
问题 I have a simple validator to validate that a String value is part of a predefined list: public class CoBoundedStringConstraints implements ConstraintValidator<CoBoundedString, String> { private List<String> m_boundedTo; @Override public void initialize(CoBoundedString annotation) { m_boundedTo = FunctorUtils.transform(annotation.value(), new ToLowerCase()); } @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (value == null ) { return true; } context