簡體   English   中英

com.mysql.jdbc.MysqlDataTruncation:數據截斷:第1行的列'DATE'的數據太長

[英]com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'DATE' at row 1

我的實體類:

@Entity
@Table(catalog = "emp", name = "person")
@XmlAccessorType(XmlAccessType.FIELD)
public class Person implements Serializable {
private static final long serialVersionUID = 1L;

/**
 */

@Column(name = "ID", nullable = false,length = 50)
@Basic(fetch = FetchType.EAGER)
@Id
@XmlElement
String id;
/**
 */

@Column(name = "ADDRESS", length = 50)
@Basic(fetch = FetchType.EAGER)
@XmlElement
String address;
/**
 */

@Column(name = "EMAIL", length = 50)
@Basic(fetch = FetchType.EAGER)
@XmlElement
String email;



@Column(name = "DATE")
@Basic(fetch = FetchType.EAGER)
@XmlElement
DateTime date;
/**
 */

/*getters and setters */

}

我正在使用joda時間來約會。 當我堅持時,它拋出了這個異常:

引起:com.mysql.jdbc.MysqlDataTruncation:數據截斷:第1行的列'DATE'的數據太長

我的日期字段包含此值:2015-09-02T16:24:05.226 + 04:00

下面是db中持久存儲的代碼:

    public Person save(Person person) {

    Person currentPerson = entityManager.find(Person.class,
            person.getId());
    if (currentPerson != null) {
        entityManager.detach(currentPerson);
        person =entityManager.merge(person);
    } else {
        entityManager.persist(person);
    }
    return person;
}

我正在使用hibernate / jpa和mysql。 我的數據庫是基於我的實體類創建的。 我的日期是我的實體類中的datetime類型,但在數據庫中它的類型為tinyblob。

看來你不能在Datetime: mysql中使用毫秒

在創建新表時,在SQL代碼中使用Datetime而不是Date

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM