无法将[java.lang.String]类型的值转换为必需类型[java.lang.Long]

时间:2017-01-20 17:29:06

标签: java spring hibernate spring-mvc spring-boot

我正在Java 8使用Spring 4.3.1.RELEASEHibernate 5.2.1.FinalMySQLWildfly 10服务器上运行。

我在Windows机器上运行服务器时有一些Java代码正常工作。但是,由于我将完全相同的代码移动到MacOS(Sierra)机器上,我得到以下内容。

我收到以下错误

  

org.springframework.web.method.annotation.MethodArgumentTypeMismatchException:   无法将[java.lang.String]类型的值转换为所需类型   [java.lang.Long中];嵌套异常是java.lang.NumberFormatException:   对于输入字符串:" null"

对我而言,由于String已分配给Long,因此看起来有错误。正如您在下面的代码中看到的那样,avatar列是带有byte[]注释的@Lob

更多细节:

19:07:23,287 WARN  [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (default task-3) Failed to bind request element: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type [java.lang.String] to required type [java.lang.Long]; nested exception is java.lang.NumberFormatException: For input string: "null"
19:07:23,423 WARN  [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (default task-5) Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Failed to decode VALUE_STRING as base64 (MIME-NO-LINEFEEDS): Illegal character ':' (code 0x3a) in base64 content
 at [Source: java.io.PushbackInputStream@57905ec8; line: 19, column: 20]
 at [Source: java.io.PushbackInputStream@57905ec8; line: 19, column: 13] (through reference chain: com.jobs.spring.domain.Person["avatar"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Failed to decode VALUE_STRING as base64 (MIME-NO-LINEFEEDS): Illegal character ':' (code 0x3a) in base64 content
 at [Source: java.io.PushbackInputStream@57905ec8; line: 19, column: 20]
 at [Source: java.io.PushbackInputStream@57905ec8; line: 19, column: 13] (through reference chain: com.jobs.spring.domain.Person["avatar"])
19:07:29,140 INFO  [org.hibernate.hql.internal.QueryTranslatorFactoryInitiator] (default task-6) HHH000397: Using ASTQueryTranslatorFactory

我的代码如下:

Person.java

import javax.persistence.*;
    ...

@Entity
@Table(name = "person")
@XmlRootElement(name = "person")
public class Person extends AbstractDomain<Long> {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Size(min = 1, max = 45)
    @Column(name = "UID")
    private String uid;

    @Basic(fetch = FetchType.LAZY)
    @Lob
    @Column(name = "AVATAR", nullable = true)
    private byte[] avatar;

    @XmlElement
    public byte[] getAvatar() {
        return avatar;
    }

    public void setAvatar(byte[] avatar) {
        this.avatar = avatar;
    }
}

MySQL人员表

enter image description here

任何帮助表示感谢。

0 个答案:

没有答案