Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 602
Box Avatar asked Feb 12 '23 02:02

Box


1 Answers

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

like image 70
JB Nizet Avatar answered Feb 13 '23 20:02

JB Nizet