[英]Hibernate + Mysql : Data truncation: Incorrect datetime value
All,全部,
I am using Spring, Hibernate and MySQL to persist some records to a queue which I process later.我正在使用 Spring、Hibernate 和 MySQL 将一些记录保存到我稍后处理的队列中。
Since I am using Java 8, the recommendation is to use JodaTime library rather than Java SQL Date cf here由于我使用的是 Java 8,因此建议使用 JodaTime 库而不是 Java SQL Date cf here
Model模型
@Entity
@Table(name = "order_job_queue")
public class CancelReward implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "processed_state")
private String processedState;
@Column(name = "order_reference_id")
private int orderReferenceId;
@Column(name = "creation_date", columnDefinition = "DATETIME DEFAULT")
private DateTime creationDate;
@Column(name = "last_checked_date", columnDefinition = "DATETIME DEFAULT")
private DateTime lastCheckedDate; ...
@PrePersist
protected void onCreate() {
creationDate = new DateTime().toDateTime();
}
@PreUpdate
protected void onUpdate() {
lastCheckedDate = new DateTime().toDateTime();
}
Table桌子
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`processed_state` VARCHAR(45) NOT NULL,
`order_reference_id` INT UNSIGNED NOT NULL,
`creation_date` DATETIME NOT NULL,
`last_checked_date` DATETIME NOT NULL,
Dependency Versions依赖版本
When I try to save an entity I get this stack trace complaining about truncation.当我尝试保存一个实体时,我得到这个堆栈跟踪抱怨截断。
Data truncation: Incorrect datetime value: ' ' for column 'creation_date' at row 1 Error while processing request: could not execute statement;
数据截断:日期时间值不正确:第 1 行“creation_date”列的“ ”处理请求时出错:无法执行语句; SQL [n/a];
SQL [不适用]; nested exception is org.hibernate.exception.DataException: could not execute statement
嵌套异常是 org.hibernate.exception.DataException: 无法执行语句
I've tried using Java SQL Date as well, not sure how to fix this one.a我也尝试过使用 Java SQL Date,不知道如何解决这个问题。a
Try using the standard date in java:尝试在 Java 中使用标准日期:
import java.util.Date;
java.sql.Timestamp
should also work but I never tried it myself. java.sql.Timestamp
也应该可以工作,但我自己从未尝试过。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.