我正在尝试将枚举类型持久化到数据库。初始化SessionFactory对象时出现此错误:
初始SessionFactory创建失败。org.hibernate.AnnotationException:属性org.structure.business.Accountant.permissions不支持java.util.TreeSet集合类型
我的枚举类型包装器:
@Entity(name = "PERMISSION")
public class PermissionWrapper implements Serializable {
private static final long serialVersionUID = 9086935561465328054L;
@Id
@Enumerated(EnumType.STRING)
private Permission permission;
@Override
public boolean equals(Object obj) {
if (!(obj instanceof PermissionWrapper)) {
return false;
}
PermissionWrapper permission2 = (PermissionWrapper) obj;
return permission == permission2.getPermission();
}
...
}
使用包装的实体:
@Entity(name = "ACCOUNTANT")
public class Accountant extends NormalUser {
private String companyName;
@OneToMany
private TreeSet<PermissionWrapper> permissions;
...
}
用于存储唯一包装的枚举的处理程序:
public class Permissions {
private static TreeSet<PermissionWrapper> permissions;
static {
System.out.println("Initialization of permissions...");
setPermissions(initPermissionsTreeSet());
}
private static TreeSet<PermissionWrapper> initPermissionsTreeSet() {
TreeSet<PermissionWrapper> permissions = new TreeSet<>();
permissions.add(new PermissionWrapper(Permission.READ));
permissions.add(new PermissionWrapper(Permission.EDIT));
permissions.add(new PermissionWrapper(Permission.CREATE));
permissions.add(new PermissionWrapper(Permission.DELETE));
return permissions;
}
...
}
答案 0 :(得分:1)
使用
ID: demo
version: 0.0.1
applications:
- name: node1
kind: html5
path: node1
expose:
- name: node_api
properties:
url: ${app-url}
- name: node2
kind: nodejs
path: node2
parameters:
quota: 256M
memory: 256M
事实上,休眠使用其自己的实现集合。