-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Validator 4 beta example throws ConstraintDefinitionExceptio
PostPosted: Mon Jul 27, 2009 11:21 am 
Newbie

Joined: Tue Mar 27, 2007 12:25 pm
Posts: 3
The example code for the custom constraint (Chapter 3) for Validator 4.0.0.Beta2 throws this Exception. It's not very clear, but looks like there is a problem with the definition of the CheckCase annotation:


javax.validation.ConstraintDefinitionException: CheckCase contains Constraint annotation, but does not contain a payload parameter.
at org.hibernate.validation.metadata.ConstraintHelper.assertPayloadParameterExists(ConstraintHelper.java:319)
at org.hibernate.validation.metadata.ConstraintHelper.isConstraintAnnotation(ConstraintHelper.java:282)
at org.hibernate.validation.metadata.BeanMetaDataImpl.findConstraintAnnotations(BeanMetaDataImpl.java:346)
at org.hibernate.validation.metadata.BeanMetaDataImpl.findConstraints(BeanMetaDataImpl.java:406)
at org.hibernate.validation.metadata.BeanMetaDataImpl.initFieldConstraints(BeanMetaDataImpl.java:258)
at org.hibernate.validation.metadata.BeanMetaDataImpl.initClass(BeanMetaDataImpl.java:233)
at org.hibernate.validation.metadata.BeanMetaDataImpl.createMetaData(BeanMetaDataImpl.java:205)
at org.hibernate.validation.metadata.BeanMetaDataImpl.<init>(BeanMetaDataImpl.java:107)
at org.hibernate.validation.metadata.BeanMetaDataImpl.<init>(BeanMetaDataImpl.java:97)
at org.hibernate.validation.engine.ValidatorImpl.getBeanMetaData(ValidatorImpl.java:724)
at org.hibernate.validation.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:204)
at org.hibernate.validation.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
at CarTest.test_manufacturerIsNull(CarTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


Top
 Profile  
 
 Post subject: Re: Validator 4 beta example throws ConstraintDefinitionExceptio
PostPosted: Mon Jul 27, 2009 1:11 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

that's an error in the documentation. It got apparently not updated yet. The payload is a new parameter each constraints has to have. It was an addition to the latest JSR 303 specification. Have a look at this blog entry or the validator migration guide on the Hibernate wiki.

The code should look like this:
Code:
public @interface CheckCase {
   String message() default "{validator.checkcase}";
   Class<?>[] groups() default {};
   Class<? extends ConstraintPayload>[] payload() default {};
   CaseMode value();
}


--Hardy


Top
 Profile  
 
 Post subject: Re: Validator 4 beta example throws ConstraintDefinitionExceptio
PostPosted: Mon Jul 27, 2009 2:35 pm 
Newbie

Joined: Tue Mar 27, 2007 12:25 pm
Posts: 3
That solved it. Thanks.


Top
 Profile  
 
 Post subject: Re: Validator 4 beta example throws ConstraintDefinitionExceptio
PostPosted: Wed Aug 19, 2009 4:43 pm 
Newbie

Joined: Tue Jul 21, 2009 2:57 pm
Posts: 8
http://blog.hibernate.org/12026.lace ... not sure where the Severity comes from, but haven't looked extensively yet.

looks like the blog example is wrong should be same as in the spec draft.

Code:
package com.acme.severity;
public class Severity {
public static class Info extends ConstraintPayload {};
public static class Error extends ConstraintPayload {};
}
public class Address {

@NotNull(message="would be nice if we had one", payload=Severity.Info.class)
public String getZipCode() {...}

@NotNull(message="the city is mandatory", payload=Severity.Error.class)
String getCity() {...}

}


This is that I don't really understand the big benefit of payloads, especially as classes as "annotation extensions". I already recreated a bunch of constraints with special stuff added, but with the lack of portability, it doesn't offer much for me really. I might be able use them in place of creating my own constraints, but the cost would probably be as high in terms of creating these weird classes to serve as metadata.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.