Mapping Set using @ElementCollection

前端 未结 3 1468
面向向阳花
面向向阳花 2020-12-02 23:29

I have the following enum:

package ir.raysis.tcs.rule.days;

public enum Days {
    SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
    THURSDAY, FRIDAY, SATURDAY;
}
         


        
3条回答
  •  星月不相逢
    2020-12-02 23:57

    for future googlers! finally i managed to solve the problem, i just had to put the annotations somewhere else in my code ,

    @ElementCollection(targetClass = Days.class)
    @CollectionTable(name = "days", joinColumns = @JoinColumn(name = "rule_id"))
    @Column(name = "daysOfWeek", nullable = false)
    @Enumerated(EnumType.STRING)
    public Set getDays() {
        return days;
    }
    

    as you can see i wrote the annotation code above and before the getter method(instead of placing it before the attribute declaration code) and problem solved, anyone who can explain me what causes this will be appreciated. thank you

提交回复
热议问题