在JPA中有一种方法可以在Entity类中映射枚举的集合吗?或者唯一的解决方案是使用另一个域类包装Enum并使用它来映射集合?
@Entity
public class Person {
public enum InterestsEnum {Books, Sport, etc... }
//@???
Collection<InterestsEnum> interests;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Hibernate JPA实现,但当然更喜欢实现不可知的解决方案.
我正在使用带有注释的Hibernate 3.5.2-FINAL来指定我的持久性映射.我正在努力建立应用程序和一组平台之间的关系.每个应用程序都可用于一组平台.
从我所做的所有阅读和搜索中,我认为我需要将平台枚举类保持为实体,并使用连接表来表示多对多关系.我希望关系在对象级别是单向的,也就是说,我希望能够获得给定应用程序的平台列表,但我不需要找出给定平台的应用程序列表.
这是我的简化模型类:
@Entity
@Table(name = "TBL_PLATFORM")
public enum Platform {
Windows,
Mac,
Linux,
Other;
@Id
@GeneratedValue
@Column(name = "ID")
private Long id = null;
@Column(name = "NAME")
private String name;
private DevicePlatform() {
this.name = toString();
}
// Setters and getters for id and name...
}
@Entity
@Table(name = "TBL_APP")
public class Application extends AbstractEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "NAME")
protected String _name;
@ManyToMany(cascade = javax.persistence.CascadeType.ALL)
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@JoinTable(name = "TBL_APP_PLATFORM", …
Run Code Online (Sandbox Code Playgroud)