在我的 Java 程序 ..Hibernate Bean 类中定义一列,如..
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 类我正在插入 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;
}
}