Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6904663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:05:21+00:00 2026-05-27T08:05:21+00:00

i want to put set of standart constraints (like not null alphanumeric string with

  • 0

i want to put set of standart constraints (like not null alphanumeric string with length from 3 to 240 chars) on the fields (String in this case) and want to know is there a way to override some of this constraint in the model code. Also is this will be an overriding, or just validating two times for overrided annotation?

it should be something like this

@AlphanumericString
@Size(min=100, max=150) //override standart values from AlphanumericString annotation

thanks for you answers

ok, answer myself. there is @OverridesParameter wich helps to reassign nested annotation parameter

@Numerical
@Size //arbitrary parameter values
@ConstraintValidator(FrenchZipcodeValidator.class)
@Documented
@Target({ANNOTATION_TYPE, METHOD, FIELD})
@Retention(RUNTIME)
public @interface FrenchZipCode {
    String message() default "Wrong zipcode";
    String[] groups() default {};

    @OverridesParameters( {
        @OverridesParameter(constraint=Size.class, parameter="min")
        @OverridesParameter(constraint=Size.class, parameter="max") } )
    int size() default 5;

    @OverridesParameter(constraint=Size.class, parameter="message")
    String sizeMessage() default "{error.zipcode.size}";

    @OverridesParameter(constraint=Numerical.class, parameter="message")
    String numericalMessage() default "{error.zipcode.numerical}";
}

source

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:05:22+00:00Added an answer on May 27, 2026 at 8:05 am

    It’s a nice question. The JSR 303 Bean Validation specification describes validation routine in the section 3.5.

    For a given group to validate, the validation routine applied on a
    given bean instance is expected to execute the following constraint
    validations in no particular order:

    • for all reachable fields, execute all field level validations (including the ones expressed on superclasses) matching the targeted
      group unless the given validation constraint has already been
      processed during this validation routine for a given navigation path
      (see Section 3.5.1) as part of a previous group match.

    …

    The object validation routine is described as such. For each
    constraint declaration:

    • determine for the constraint declaration, the appropriate ConstraintValidator to use (see Section 3.5.3).
    • execute the isValid operation (from the constraint validation implementation) on the appropriate data (see Section 2.4)
    • if isValid returns true, continue to the next constraint,
    • if isValid returns false, the Bean Validation provider populates ConstraintViolation object(s) according to the rules defined in Section 2.4 and appends these objects to the list of constraint violations.

    In your case, you deal with validation of a simple String field where the targeted group is Default. You have two validation constraints (@AlphanumericString and @Size) which according to the documentation will be validated/processed separately in no particular order.

    So to answer your question. No, there will be no override applied to your @AlphanumericString when you use @Size additionaly. To be able to achieve what I think you attempt to do, you may create a constraint composition where you overridde attributes from composing annotations like that:

    @Pattern(regexp="[a-zA-Z]*")
    @Size
    @Constraint(validatedBy = AlphanumericStringValidator.class)
    @Documented
    @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
    @Retention(RUNTIME)
    public @interface AlphanumericString {
       // ...
      @OverridesAttribute(constraint=Size.class, name="min")
      int min() default 3
      @OverridesAttribute(constraint=Size.class, name="max")
      int max() default 230;       
       // ...
    }
    

    and use it like that:

    @AlphanumericString(min = 100, max = 150)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to put random output from my result set (about 1.5 mil rows)
Suppose I want to put objects that identify a server into a stl set
In emacs, I want to bind a command to C-i. So I put (global-set-key
I want to select a set of data into a single string, but I
I have a set of objects I want to put into an array and
I have set up a java project in Eclipse and I want to put
I want to put images in each pages of my ViewPager (like a book).
I've projected an Intranet Ajax application and I want put it in a full
hey, hi i want put limit on object creation means a class can have
I have a page layout for my MOSS '07 site that I want put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.