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 8725209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:59:22+00:00 2026-06-13T07:59:22+00:00

I have a model object which has entities annotated with hibernate validation annotations. For

  • 0

I have a model object which has entities annotated with hibernate validation annotations. For example @NotBlank, @NotNull, @Length.
I have a form backing this model which decorates an instance of the model object. I have annotated this instance with an @NotNull, @Valid annotation. I am registering a validator for this backing form in the Controller Class and the form validator is being invoked when the @RequestMapping method argument is annotated with @Valid annotation.

Note the model is also annotated with the @Entity annotation, the model backing form is just
a thin wrapper around the model.

However the validations on the decorated object are not being checked? I know this because in the request mapping method definition I check the BindResult for errors and there are none.
My form fields are all empty, hence the validations on the fields on the decorated model annotated with @NotBlank should be checked. However that does not happen.

Can you help me fix this?

Edit:
Sample Code

@Entity
class MyModel {
    @Id
@GeneratedValue(strategy = GenerationType.AUTO)
    @Column(nullable=false)
    private Long id;

    @NotBlank
    @Column(unique=true, length=30, nullable=false)
    private String number;

    @Column(length=30, nullable=false)
    @Length(min=1, max=30)
private String firstName;
    /* ... getters and setters ... */
}

public class MyModelBackingForm {

   @NotNull
   @Valid
   private MyModel model;
   /* ... delegate getters and setters for all fields in MyModel ...  */
 }

Edit:
Add Controller Code

@InitBinder
protected void initBinder(WebDataBinder binder) {
  binder.setValidator(new MyBackingFormValidator());
}

Edit:

public class MyBackingFormValidator implements Validator {

  public MyBackingFormValidator() {
    super();
  }

  @Override
  public boolean supports(Class<?> clazz) {
    return Arrays.asList(MyBackingForm.class, MyModel.class).contains(clazz);
  }

  @Override
  public void validate(Object obj, Errors errors) {
   // custom validation code commented ... as I want to check if JSR 303 validations invoked
  }
}
  • 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-06-13T07:59:24+00:00Added an answer on June 13, 2026 at 7:59 am

    Here is a sample code the way I was using the hibernate validation. I was calling @valid on the fetched objects with the binding result. This way it knows the validations which are required to be done on the form.
    Edited: How to invoke custom and standard validator?

    Using @InitBinder we can pass the custom validator instance to which again we can pass the class parameter for the standard validator using binder.getValidator()

    Courtesy: Rohit Banga

    @Controller
    @RequestMapping("/customer")
    public class CustomerController {
    

    //Edited:

    @InitBinder 
    protected void initBinder(WebDataBinder binder) { 
    binder.setValidator(new CustomFormValidator(binder.getValidator())); 
    }
    
        @RequestMapping(value = "/signup", method = RequestMethod.POST)
        public String addCustomer(@Valid Customer customer, BindingResult result) {
    
            if (result.hasErrors()) {
                return "form";
            } else {
                return "success";
            }
    
        }
    
        @RequestMapping(method = RequestMethod.GET)
        public String customerForm(ModelMap model) {
    
            model.addAttribute("customer", new Customer());
            return "form";
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a model object 'Person' defined, which has a field called 'Name'.
I have a fairly involved managed data model which has a central object with
I have a an object stored in the model called domain, which has two
In my application, we have a view model object from which we're retrieving its
I have a project which exposes object model to use by different types of
In my model, I have a base object class A which holds a set
I have a data model object User . My app also has some other
So long story short I have an object model in which several different entity
I have an entity ( TerminalCertification ) which has relation to other entities. I
I have an object which contains models for my ASP.NET MVC web app. The

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.