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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:12:24+00:00 2026-06-11T23:12:24+00:00

I am using spring 3.1 with hibernate validator 4.2. I observe that hibernate validation

  • 0

I am using spring 3.1 with hibernate validator 4.2. I observe that hibernate validation gets invoked two times:
One at controller level when i use method like:

 @RequestMapping(method = RequestMethod.POST)
    public String onSubmit(@Valid User user, BindingResult result) {....}

And 2nd time when entities are persisted as part of:

org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(..)
org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreUpdate(..)
org.hibernate.action.EntityUpdateAction.preUpdate(..)

I believe it makes more sense to valid at controller level and display error page with error messages. And anyway, doing same validation two times in flow not good.
I found in hibernate doc that it can be turned off by setting hibernate.validator.autoregister_listeners to false in hibernate configuration but it is not recommended.

So what is recommended approach for validation? Also in my particular case 2nd validation causes trouble because I have a field ‘confirmPassword‘ which is required for validation when user submits form but is not required in table so whenever i have to save, update user, I have to set confirmPassword field unnecessarily just to make validation pass.

  • 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-11T23:12:25+00:00Added an answer on June 11, 2026 at 11:12 pm

    Validation isn’t an easy thing in spite of appearances.

    The frontend validation is for the user that fills the form,and could change from a view to another view (different messages for example). The message for a required field in the view should be “The field is mandatory !”, in the backend when the entity is persisted : “field cannot be null”.

    The backend validation should occur ALWAYS when a class is saved, consider infact that a persistent entity could be saved without passing from the view (for example from a batch that receive data from a webservice or from queues ora another source..).

    If you put a validation annotation at entity level you enforce a contract on that class that is independent from the fact that the class has been used in a view or not.

    ConfirmPassword is a view field, so i think should not be present as field in the entity (for example, I developed a similar case with JSF, i put confirmPassword in the ManagedBean related to that view and not in the entity, the entity contain only the password field).

    Summarizing therefore i think is correct doing the ‘same’ validation twice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using spring based validation in combination with hibernate validator enabled by the following
I create form and controller this form have some validation constrains using Hibernate validator.
First, let me explain that I'm using Spring MVC 3.1.1, and Hibernate validation 4.2.0.
I'm using Hibernate Validator 4.0.2, Spring 3.0 and Hibernate 3.3.2 (which, as I understand
I'm working on a Spring MVC project in which I'm using Hibernate Validator to
I am using Spring MVC with Hibernate. My page has a button that creates
I'm using Hibernate Validator in an application with EJB and Spring MVC. I'm using
i am using hibernate validation (4.2.0 Final) with JSF 2 and Spring and here's
I have an app using Spring, JPA (Hibernate) and the Java validation framework (Hibernate
I'm using hibernate validator framework with Spring. A class implementing the Spring Validator validates

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.