No validator could be found for type: java.lang.Long. with post ID

10,973

The problem probably is this line:

@NotBlank
@Column(name="thread_id")
private long thread_id;

NotBlank has no sense on a field of type long. A long can't be blank or not blanked. Only a String can. Hence the error message:

javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.Long

Share:
10,973
Box
Author by

Box

Updated on June 25, 2022

Comments

  • Box
    Box almost 2 years

    What's wrong with my program? I get error

    HTTP Status 500 - Request processing failed; nested exception is javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.Long.
    

    And don't know how to solve it... On the stack trace the only class written by me is

    myapp.spring.controllers.PostFormController.processForm(PostFormController.java:66)
    

    And this line is

    validator.validate(p, result);
    

    Post.java

    // imports
    
    @Entity
    @Table(name="posts")
    public class Post implements Serializable
    {
            /* **********************************
             * ------------ fields ------------ *
             ************************************/
            /**
             *
             */
            private static final long serialVersionUID = 1L;
    
            @Id
            @GeneratedValue(strategy=GenerationType.IDENTITY)
            private long id;
    
            @Past
            @Column(name="date")
            private Date date;
    
            @NotBlank
            @Size(min=3, max=20)
            @Column(name="author")
            private String author;
    
            @NotBlank
            @Column(name="content")
            private String content;
    
            @NotBlank
            @Column(name="topic")
            private String topic;
    
            @NotBlank
            @Column(name="thread_id")
            private long thread_id;
    
            @ManyToOne
            @JoinColumn(name="name")
            @Valid
            private PostType type;
    
    
    
            /* ***************************************
             * ---------- getters setters ---------- *
             *****************************************/
           // cut // 
    
    }
    

    blah blah blah can't add because of too much code in post :S

    • JB Nizet
      JB Nizet over 9 years
      and p is a Long, right? What do you expect the validation of a Long variable to do? What don't you understand in the error message?
    • Box
      Box over 9 years
      p is a Post type from http method POST public String processForm(Model model, @ModelAttribute("post") Post p, BindingResult result)
    • JB Nizet
      JB Nizet over 9 years
      Show us the code of Post.
    • Box
      Box over 9 years
    • JB Nizet
      JB Nizet over 9 years
      In your question. Not on pastebin. Use the edit link.
    • Box
      Box over 9 years
      Added the code. I solved it with my friend's help: changed long to Long... Somebody can explain why is it make a difference?
    • Giovanni Botta
      Giovanni Botta over 9 years
      Your question does not provide enough information for us to understand and help with your issue. A complete code example with your Spring config file would be helpful. If the code is too long, try to get rid of the parts that do not affect the issue.
  • Box
    Box over 9 years
    I added NotBlank because I thought lack of this causes that problem. Forgot to delete, sorry. The problem Was with long. I've changed to Long and now it works properly :D Thank you.