Mapping Set using @ElementCollection

前端 未结 3 1470
面向向阳花
面向向阳花 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-03 00:06

    While the other question is correct, the most simple form could be:

    @ElementCollection
    @Enumerated
    private Set enumValues;
    

    everything else would be set by convention over configuration (join-table-name, columns).

    I highly recommend using @Enumerated(EnumType.STRING) - look it up why. And you might need @ElementCollection(fetch = FetchType.EAGER) depending on what (and where) you're doing.

提交回复
热议问题