JPA map collection of Enums

后端 未结 6 702
滥情空心
滥情空心 2020-11-27 12:46

Is there a way in JPA to map a collection of Enums within the Entity class? Or the only solution is to wrap Enum with another domain class and use it to map the collection?<

6条回答
  •  日久生厌
    2020-11-27 13:22

    Collections in JPA refer to one-to-many or many-to-many relationships and they can only contain other entities. Sorry, but you'd need to wrap those enums in an entity. If you think about it, you'd need some sort of ID field and foreign key to store this information anyway. That is unless you do something crazy like store a comma-separated list in a String (don't do this!).

提交回复
热议问题