在Hibernate中映射EnumSet [英] Mapping EnumSet in Hibernate
问题描述
如何在数据库中存储EnumSet(使用Hibernate)?
@Entity
public class A
{
public static enum SOME_ENUM {A,B,C};
私人EnumSet< SOME_ENUM> myEnumSet = EnumSet.of(SOME_ENUM.A,SOME_ENUM.B);
...
...
}
<如果我试图坚持以上,我当然会得到例外。
我想使用@CollectionOfElements,但不推荐使用。是否有任何其他的@CollectionOfElements?
有没有一种方法可以在不写UserType的情况下将EnumSet存储在单个列中?
谢谢!
这并不是说这很难。请参阅此文档 https:/ /forum.hibernate.org/viewtopic.php?p=2300843 How to store EnumSet in the DB (using Hibernate)? If I try to persist the above, I get exception of course.
I wanted to use @CollectionOfElements, but it is deprecated. Is there any alternative of @CollectionOfElements? Is there a way to store EnumSet in a single column without writing UserType? Thanks! hibernate does not have built in support for such things. Note that when dealing with hibernate and collections you should really only be specifying an interface; in this case Set. Hibernate proxies all collections so it can efficiently deal with lazy loading. This is not to say this is difficult. See this documentation https://forum.hibernate.org/viewtopic.php?p=2300843 这篇关于在Hibernate中映射EnumSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
@Entity
public class A
{
public static enum SOME_ENUM { A, B, C };
private EnumSet<SOME_ENUM> myEnumSet = EnumSet.of(SOME_ENUM.A, SOME_ENUM.B);
...
...
}