在我的Java程序..Hibernate Bean類定義一個列如..如何在Mysql數據庫中避免'數據被截斷'使用java?
TimtableVO.java
@Column(name="REPEAT_DAYS")
private WeekdayType repeatDays;//hear WeekdayType is Enum Class
在我的服務類我使用這個TimetableVO.java bean類的。 。
這是我的服務類:
public void createEvent(TimetableVO timetableVO) {
WeekdayType weekday = null;
for (String day : timetableVO.getTemp().split(",")) {
weekday = WeekdayType.valueOf(day);
}
timetableVO.setRepeatDays(weekday);
userDAO.createEvent(timetableVO);
}
我的DAO類我是我nserting timetableVO對象..
public void createEvent(TimetableVO timetableVO) throws DataAccessException {
entityManager.persist(timetableVO);
}
但是異常會..
Exception: Caused by: java.sql.BatchUpdateException: Data truncated for column 'REPEAT_DAYS' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2045)
at coHibernate: insert into EC_TIMETABLE (CLASS_DURATION, COURSE_DURATION, COURSE_FEE, END_DATE, REPEAT_COUNT, REPEAT_DAYS, REPEAT_TYPE, SEARCH_KEY, START_DATE, S_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
m.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1468)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 65 more
Caused by: java.sql.SQLException: Data truncated for column 'REPEAT_DAYS' at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
編輯: 這是我WeekdayType枚舉
public enum WeekdayType {
MONDAY(Calendar.MONDAY), TUESDAY(Calendar.TUESDAY), WEDNESDAY(
Calendar.WEDNESDAY), THURSDAY(Calendar.THURSDAY), FRIDAY(
Calendar.FRIDAY), SATURDAY(Calendar.SATURDAY), SUNDAY(
Calendar.SUNDAY);
private int day;
private WeekdayType(int day) {
this.day = day;
}
public int getDay() {
return day;
}
}
向我們展示您的WeekdayType –
列'REPEAT_DAYS'的數據類型是什麼數據類型 –
枚舉類型....即,WeekdayType。 –