1

In my Java Program Enum like this..

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;
    }
}

And my Hibernate bean define like this my TimetableVO.java

    @Column(name="REPEAT_DAYS")
@Enumerated(EnumType.STRING)
private WeekdayType repeatDays;// And Setter and Getters....

In my Service class i'm Doing like this..

String totalDays="MONDAY,SUNDAY,FRIDAY,SATURDAY"
    public void createEvent(TimetableVO timetableVO) {
    WeekdayType weekday = null;
    for (String day : totalDays.split(",")) {
        weekday = WeekdayType.valueOf(day);
    }
    timetableVO.setRepeatDays(weekday);
......
......
......
entityManager.persist(timetableVO);     



    }

But the Problem is In database column Adding Last Value Only...that mean it Override Previous value

For Ex:above String SATURDAY only inserting on Database but i want to insert all values like MONDAY,SUNDAY,FRIDAY,SATURDAY...give me Suggestion..

Java Developer
  • 1,873
  • 8
  • 32
  • 63
  • Correct i want List of Days in my column..but in Hibernate Bean class Define like this private List repeatDays; but it is Asking Some relation or Error. – Java Developer Dec 19 '12 at 11:30

2 Answers2

2

change your column type

private WeekdayType repeatDays;

should be changed to String type

private String repeatDays;

set your csv to this column.

Other option is to have

private List<WeekdayType> repeatDays; with @JoinTable annotation

which will create another mapping table. to handle manytomany relation.

Subin Sebastian
  • 10,870
  • 3
  • 37
  • 42
1

Trying to save more values in a single column is a conceptual error in a relational database. A solution could be to create another table, and create a relation between your TimeTable and the newly created table.

A second, less flexible alternative, could be create 7 different properties (and also seven different columns) each one relative to a single day, without creating a new table, so you could have:

 @Column(name="MONDAY")
 private boolean repeatOnMonday;

 @Column(name="TUESDAY")
 private boolean repeatOnTuesday;

 //...
Atropo
  • 12,231
  • 6
  • 49
  • 62