0
我有一個問題與使用Java 休眠與MySQL的存儲列屬性年。休眠轉換的Java日期到MySQL YEAR
MySQL表:
CREATE TABLE DateTest (
id INT NOT NULL AUTO_INCREMENT,
year YEAR(4),
PRIMARY KEY(id)
) ENGINE = InnoDB;
..
Java訪問類
public class DateTest implements java.io.Serializable {
private Integer id;
private Date year;
public DateTest() {
}
public DateTest(Date year) {
this.year = year;
}
public Integer getId(){
return this.id;
}
public void setId(Integer id){
this.id = id;
}
public Date getYear(){
return this.year;
}
public void setYear(Date year){
this.year = year;
}
}
Java代碼來保存記錄
DateTestDao tcd = new DateTestDao();
Date dd = new Date();
DateTest dt = new DateTest();
tc.setYear(dd);
tcd.saveRecord(dt);
當我想用Hibernate的session.save出現以下錯誤:
錯誤org.hibernate.util.JDBCExceptionReporter - 數據截斷「年」列在第1行
Prinicpally,我知道它爲什麼會發生,因爲該日期元素較大比允許的年份屬性,但我不知道如何解決它。
最好的問候, 邁克爾