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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:10:40+00:00 2026-06-07T13:10:40+00:00

I have a very naive conceptual question here for clarification. In my app I’m

  • 0

I have a very naive conceptual question here for clarification. In my app I’m currently using JSR 303 Hibernate Validator for validating the domain model with @NotBlank and @NotNull annotations, like checking username, password etc.

public class Admin {

  private Long id;
  @NotBlank(message = "Username should not be null")
  private String username;
  @NotBlank(message = "Username should not be null")
  private String password;
  ...

But for validating the domain logic like existing username, I’m still using Spring’s Validator interface

@Component
public class AdminValidator implements Validator {
  ...
  @Override
  public void validate(Object target, Errors errors) {
    Admin admin = (Admin) target;
    if (usernameAlradyExist())){
        errors.rejectValue("username", null, "This user already exist's in the system.");
    }

}

In the controller I’m using both

@RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(@Valid @ModelAttribute("admin") Admin admin, BindingResult bindingResult,) {
    validator.validate(admin, bindingResult);
    if (bindingResult.hasErrors()) {
        return REGISTER_ADMIN.getViewName();

    }

Is it possible just to use Hibernate Validator and not at all use Spring Validator for validating domain logic?

  • 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-07T13:10:44+00:00Added an answer on June 7, 2026 at 1:10 pm

    Yes, You can use JSR validation for your domain logic validation. You need to define custom constraint annotations and define your domain logic validation inside it.
    Like
    Defining custom constraint annotation UserExistsConstraint

    @Target({ElementType.FIELD})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @Constraint(validatedBy=UserExistsConstraintValidator.class)
    
    public @interface UserExistsConstraint {
     String message() default "This user already exist's in the system.";
     Class<!--?-->[] groups() default {};
     Class<!--? extends Payload-->[] payload() default {};
    }   
    

    Defining validator for custom annotation.

    public class UserExistsConstraintValidator implements ConstraintValidator<UserExistsConstraint, object=""> {
    
     @Override
     public void initialize(UserExistsConstraint constraint) {
    
     }
    
     @Override
     public boolean isValid(Object target, ConstraintValidatorContext context) {
       if (usernameAlradyExist())
       {    
         return false;
       }
       else
       {
         return true; 
       }    
     }
    }
    

    Using custom annotation

    public class Admin {
    
      private Long id;
      @NotBlank(message = "Username should not be null")
      @UserExistsConstraint
      private String username;
      @NotBlank(message = "Username should not be null")
      private String password;
      ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if the question is very naive. I will have to check the below
I have a very naive question. How to display subscripts in the Django form?
Probably a very naive question: I have a list: color = [red,blue,red,green,blue] Now, I
The question I have is very specific. I wanted to have an app where
I have very little experience using Sharepoint but a good amount using Visual Studio
A naive question: As most developers, I periodically have a need to save data
This probably comes across as a very naive question, and I am absolutely assuming
It maybe a little naive question but I have been trying to understand how
I have built a very naive parallel ssl acceptor. -module(multiserver). -export([start/0,client/1]). %% This is
My question may sound naive, but really struggling to do a very simple thing.

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.