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

4

32

I have to update information in my database.

FacadePatient.java class code:

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;
}
Memorable answered 12/6, 2013 at 20:21 Comment(5)
OK, so what's the problem, that you're getting the validator exception, or that you don't know where to begin?Alcibiades
it gives this error : javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.Integer,Latticework
I have also changed the attribute Type from integer to string but the same errorLatticework
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.From
This question is related also to javax.servlet.ServletException: HV000030: No validator could be found for type: java.util.Date. Regards,Abroad
F
110

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

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.

From answered 13/6, 2013 at 11:56 Comment(3)
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;Blinkers
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.Firearm
@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. #27527253From
P
14

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;
Puca answered 13/3, 2016 at 20:55 Comment(2)
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.Piecework
This could also be the cause. the size things on int, boolean, tinyint cause this issue. thanks for the commentOverunder
D
4

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.

Decapod answered 16/5, 2017 at 14:35 Comment(0)
E
0

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

  • @Length(max = 3)
  • @Size
Ephemeral answered 10/10, 2018 at 20:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.