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
Author by
Box
Updated on June 25, 2022Comments
-
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 over 9 yearsand
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 over 9 years
p
is aPost
type from http method POSTpublic String processForm(Model model, @ModelAttribute("post") Post p, BindingResult result)
-
JB Nizet over 9 yearsShow us the code of Post.
-
Box over 9 years@JBNizet pastebin.com/pJhiAh3R
-
JB Nizet over 9 yearsIn your question. Not on pastebin. Use the edit link.
-
Box over 9 yearsAdded the code. I solved it with my friend's help: changed
long
toLong
... Somebody can explain why is it make a difference? -
Giovanni Botta over 9 yearsYour 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 over 9 yearsI added
NotBlank
because I thought lack of this causes that problem. Forgot to delete, sorry. The problem Was withlong
. I've changed toLong
and now it works properly :D Thank you.