Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

javax.servlet.ServletException: HV000030: No validator could be found for type: java.lang.Integer

Ask Question
public Patient update(Patient p) {
    Patient pat = em.find(Patient.class, p.getPatientId());
    p.setPatientPhone(pat.getPatientPhone());
    p.setPatientDateNaiss(pat.getPatientDateNaiss());
    p.setPatientEmail(pat.getPatientEmail());
    p.setPatientJob(pat.getPatientJob());
    p.setPatientSmoking(pat.getPatientSmoking());
    p.setPatientSize(pat.getPatientSize());
    em.merge(pat);
    return p;
                OK, so what's the problem, that you're getting the validator exception, or that you don't know where to begin?
– JoshDM
                Jun 12, 2013 at 20:28
                it gives this error : javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.Integer,
– Héla
                Jun 12, 2013 at 20:30
                Because it's not a JSF or PrimeFaces problem. If you have nailed down the one throwing this exception by just looking at the stack trace (javax.validation.UnexpectedTypeException would appear as root cause; its package name javax.validation in turn hints a problem in JSR303 bean validation; the HVxxxxxx error code in turn hints a problem from Hibernate Validator), then you would have tagged this question as [bean-validation] and the question would be so much faster understood/answered then. All the JSF code posted so far is only irrelvant.
– BalusC
                Jun 13, 2013 at 12:00
                This question is related also to javax.servlet.ServletException: HV000030: No validator could be found for type: java.util.Date. Regards,
– Rodmar Conde
                Oct 13, 2014 at 21:27

That will happen when you use JSR303 bean validation in flavor of Hibernate Validator and you have in your JPA entity the Hibernate-specific @NotEmpty on an Integer property like this:

@NotEmpty
private Integer some;

This is completely wrong. An integer cannot be considered as a string, collection, map or array. Use the standard @NotNull instead.

@NotNull
private Integer some;

Please note that the concrete problem is completely unrelated to JSF. In the future, please learn how to exclude as much as possible noise and naildown the concrete problem by e.g. executing the JPA code individually. JSF is merely the HTTP/MVC messenger here and PrimeFaces is merely the HTML/CSS/jQuery/UI code generator.

Well I run across the same error in a different (but highly stupid) scenario: @Pattern(regexp = "[1-9][0-9]{9}", message = "Phone numbers are 10 digit numbers") private int phoneNumber; --> corrected by merely :private String phoneNumber; – Mr_and_Mrs_D Feb 2, 2014 at 22:40 The same error occurs with @Size(max=2). For some reason, Apache MyFaces 2.2 shows the error in an alert box in my JSF application, whereas Oracle's Mojarra doesn't. – Stephan Rauh Feb 12, 2015 at 21:30 @Stephan: That will happen when an exception is thrown during an ajax request (check server logs!). Mojarra only shows that alert during development stage. This problem is unrelated to the question currently asked. See also a.o. stackoverflow.com/questions/27526753/… – BalusC Feb 12, 2015 at 21:32

I'd like to add to the above answer. This exception would also be thrown when you have some thing for example like this:

@Size(min = 1, max = 20)
@Column(name = "ID")
private int id;
                I got this error in same situation. But why do we get this error. Because previously it was working in my project. Later i got this error due to @Size.
– Hema
                Jul 10, 2017 at 12:30
                This could also be the cause. the size things on int, boolean, tinyint cause this issue. thanks for the comment
– Ishimwe Aubain Consolateur
                May 12, 2018 at 11:07

You may get this problem also in instances like below;

@Size(max = 45, message = "Field 'SomeEntityClass.yourEnumType' cannot exceed 45 characters") @Column(length=45)
@Enumerated(EnumType.STRING)
private SomeEnumType yourEnumType;

This is because at validation time the ordinal value of 'yourEnumType' (which is of integer type) is processed ahead of the String mapping which Hibernate resolves before storing the value to the database.

Also if any constraint not valid for integer is present it would throw that error. Like annotating an Integer with:

  • @Length(max = 3)
  • @Size
  • Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.