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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:22:54+00:00 2026-06-15T00:22:54+00:00

Good Afternoon, I am having problem to inject a service within a Bean Validator

  • 0

Good Afternoon,

I am having problem to inject a service within a Bean Validator (JSR 303). I would be performing a validation, but I need to validate this record in my database;

When I use my service it throws NullPointerException;

Exception:

Exception in thread "main" javax.validation.ValidationException: HV000028: Unexpected exception during isValid call.
at org.hibernate.validator.internal.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:294)
at org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:164)
at org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:125)
at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:86)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:442)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:387)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:351)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:303)
at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:133)
at net.pontoall.hemisphere.core.validation.impl.TesteValidator.main(TesteValidator.java:25)



Caused by: java.lang.NullPointerException
at net.pontoall.hemisphere.core.validation.impl.UsuarioValidatorImpl.doCheckLogin(UsuarioValidatorImpl.java:48)
at net.pontoall.hemisphere.core.validation.impl.UsuarioValidatorImpl.isValid(UsuarioValidatorImpl.java:26)
at net.pontoall.hemisphere.core.validation.impl.UsuarioValidatorImpl.isValid(UsuarioValidatorImpl.java:1)
at org.hibernate.validator.internal.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:291)
... 9 more

Annotation:

@Target(value = ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = UsuarioValidatorImpl.class)
public @interface UsuarioValidator {

String message() default "{net.pontoall.hemisphere.validation.UsuarioValidator.message}";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};

}

ValidatorImpl:

public class UsuarioValidatorImpl implements ConstraintValidator<UsuarioValidator, Usuario> {

@Autowired
private IUsuarioService service;

@Override
public void initialize(UsuarioValidator arg0) {

}

@Override
public boolean isValid(Usuario entidade, ConstraintValidatorContext ctx) {
    try {
        return (this.doCheckLogin(entidade, ctx) && this.doCheckEmail(entidade, ctx));
    } catch (HemisphereException e) {
        e.printStackTrace();
        return false;
    }
}

private boolean doCheckLogin(Usuario entidade, ConstraintValidatorContext ctx) throws HemisphereException {
    ctx.buildConstraintViolationWithTemplate("{net.pontoall.hemisphere.validation.UsuarioValidator.login.message}").addConstraintViolation();

    if (entidade.getId() == null) {
        // Novo Usuário
        Usuario original = service.buscarPorLogin(entidade.getLogin());

        if (original == null) {
            return true;
        }

        return false;

    } else {

        Usuario original = service.obter(entidade.getId());
        if (original == null) {
            return true;
        } else {
            if (original.getLogin().equals(entidade.getLogin()) && original.getId().equals(entidade.getId())) {
                return true;
            }
        }

        return false;
    }
}

private boolean doCheckEmail(Usuario entidade, ConstraintValidatorContext ctx) {
    ctx.buildConstraintViolationWithTemplate("{net.pontoall.hemisphere.validation.UsuarioValidator.email.message}").addConstraintViolation();

    if (entidade.getId() == null) {
        // Novo Usuário
        Usuario original = service.buscarPorEmail(entidade.getEmail());

        if (original == null) {
            return true;
        }

        return false;

    } else {

        Usuario original = service.obter(entidade.getId());
        if (original == null) {
            return true;
        } else {
            if (original.getEmail().equals(entidade.getEmail()) && original.getId().equals(entidade.getId())) {
                return true;
            }
        }

        return false;
    }
}
}
  • 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-15T00:22:56+00:00Added an answer on June 15, 2026 at 12:22 am

    You should set up a LocalValidatorFactoryBean in your Spring application context so you can retrieve Validator (and ValidatorFactory) instances via dependency injection.

    By default, a validator obtained like that makes use of SpringConstraintValidatorFactory which provides dependency injection services to constraint validator implementations, as pointed out by Pangea.

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

Sidebar

Related Questions

Good afternoon, I'm having a problem with a section of code I'm working on
Good afternoon. I'm having a problem resizing a listview in a form. In the
Good afternoon, I'm still fairly new to XMl and DTD's but I'm having fun
Good afternoon, I'm having serious troubles getting my database back up and running. I
Good Afternoon all , I have downloaded data from a web service and im
Good Afternoon, I am having a hard time setting the navigational links to active
Good afternoon all, I was taught that when a function returns, The variables (within
Good afternoon. I am starting with Visual c++ and I have a compilation problem
Good afternoon, I am having difficulties with libxml2. I tried to build the Perl
Good afternoon all, I dont know why this is proving so difficult but I

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.