Q:

java.util.TreeSet collection type not supported for custom wrapped enum type

I am trying to persist enum type to database. while initializing SessionFactory object I got this error:

Initial SessionFactory creation failed.org.hibernate.AnnotationException: java.util.TreeSet collection type not supported for property: org.structure.business.Accountant.permissions

My wrapper for enum type:
@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 that uses wrapper:
@Entity(name = "ACCOUNTANT")
public class Accountant extends NormalUser {
private String companyName;

@OneToMany
private TreeSet<PermissionWrapper> permissions;
...
}

Handler for storing unique wrapped enums:
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;
}
...
}

A:

Use
@OneToMany
private Set<PermissionWrapper> permissions;

In fact hibernate use its own implementation of collection.

