-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Validator: Attribute Overriding
PostPosted: Wed Jul 10, 2013 1:29 pm 
Newbie

Joined: Wed Jul 10, 2013 1:12 pm
Posts: 2
Hi

I am currently working on my master thesis using Hibernate Validator and it is really great. While working with the library, I came up with the following question:

I have the following constraint which is a constraint composition:

Code:
@ConstraintComposition(CompositionType.OR)
@Deadline
@Min(value = 0)
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = { })
@ReportAsSingleViolation
public @interface MinOnDeadline {
   
    Class<? extends Payload>[] payload() default {};
   
    String message() default "the deadline has expired.";

    Class<?>[] groups() default {};
   
    @OverridesAttribute(constraint=Min.class, name="value")
    long value();
   
}


Why do I have to specify a value for the @Min(value = 0) annotation?

Thank you very much.
Oliver


Top
 Profile  
 
 Post subject: Re: Hibernate Validator: Attribute Overriding
PostPosted: Thu Jul 11, 2013 3:08 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi Oliver,


The attribute has no default value, meaning it must be specified when using @Min. Otherwise the code won't compile. This is to prevent using the constraint in a wrong way by "forgetting" to set a value.

In the case of composition where the attribute is overridden this is a little bit uncomfortable, but the advantages of ensuring proper usage in the vast majority of use cases outweigh this. Which value you specify here doesn't matter as it is overridden anyways.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.