JPA - No validator could be found for type: enum

末鹿安然 提交于 2019-12-03 09:44:10

I had the same error as you. The problem with mine was that I had mistakenly placed @Size on my enum property:

public class PhoneNumber {
  @Size(max=30) //ERROR: this validation annotation is what caused my error
  @Nonnull
  @Enumerated(EnumType.STRING)
  private Type type;
  @Size(max = 30)
  @Nonnull
  private String number;

  public enum Type {
    Cell, Home, Work, Other
  }
}

Once I removed the erroneous @Size, my error went away.

@Enumerated didn't cause any problems for me, and I doubt @Column would. Perhaps you had another validation annotation you skimmed over like I did.

For my testing, I was using hibernate-validator-4.1.0-Final.jar

I came across the same situation, but with the message No validator could be found for type int. searching the web I found some solutions, most of them focus on changing type int to type Integer, because type Integer accept nulls. like in here : Validation - Empty int field

unfortunately that didn't work for me. but when I substituted @size with @Min and @Max everything went great. hoping this may gives you a hand.

I had the same error as you but the message was "No validator could be found for type: java.lang.Long. I had spent a lot of time reviewing the code until I saw the previous solution and thus, I removed all @Size entries from the entity code and also the problem went away. I should actually find out which is the offending line in the entity source code but coming from another more developer friendly platform (IBM i Series) I'll wait until the error messages are improved to give us better and accurate reasons.

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