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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:39:30+00:00 2026-06-17T22:39:30+00:00

I read many tutorials about JSR 303 spec, but I don’t see any example

  • 0

I read many tutorials about JSR 303 spec, but I don’t see any example ready for production. Everywhere described how to get Set<Constraintviolation<T>> object.

Example:

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
Set<ConstraintViolation<Car>> violations = validator.validate(car);

But what next? I want to inform method caller (client) that method parameter is in inconsistent state.

What I must do with Set<ConstraintViolation<Car>>? I need manually iterate over Set<ConstraintViolation>, collecting all error messages into one string, and then throw an exception with this messages?

Or exist some more convenient ways out of the box?

Or it’s better to provide validate method inside each bean?

  • 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-17T22:39:31+00:00Added an answer on June 17, 2026 at 10:39 pm

    I would go with your first suggestion – iterate over the constraint violations. You don’t necessarily create an error message that contains all that stuff. It is probably a good idea to just have an error message saying bean <bean> is not valid and set the constraint violations as a property on an exception.

    Maybe you need to convert the constraint violations to another object, because otherwise you would make much of your application dependent on the bean validation api. That might be a too strong coupling.

    Your problem is that it is very use case specific what to do with the constraint violations. There are many cases where you don’t want to inform the caller about the constraint violations, but some other object. For example in a web form you want to inform your view model that it should also display these constraint violations. Throwing an exception is just another thing. Note that this won’t be a ConstraintViolationException in most cases, but a application specific exception.

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

Sidebar

Related Questions

I read many question about that and tutorials, but the only one executed, and
I learn about current NSXMLParser. I read many tutorials but none could tell me
I am confused about the a concept here. I read on many tutorials that
I've read and watched many tutorials on NSUserDefaults in the iPhone OS/iOS SDK, but
I am using vbulletin 4.1.7 I've read many tutorials out there but none explais
I have read many questions and tutorials about this, I couldn't find a case
I read many tutorials but I could not get this running for my project.
I've read many tutorials about MVC method ... I am now about to start
What does the ALIGN keyword do in linker scripts? I read many tutorials about
I have read many tutorials on the internet about the usage of the 'tr'

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.