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

匿名 (未验证) 提交于 2019-12-03 01:09:02

问题:

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; }

回答1:

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.



回答2:

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;


回答3:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!