I tried the aforementioned solution but it's still not working. I am still getting an "Object Role must declare a default (no argument) constructor" exception from Hibernate.
Here is the pretty standard PersistentEnum class.
Code:
public class Role implements PersistentEnum {
private final int roleEnumID;
private Role(int roleEnumID){
this.roleEnumID = roleEnumID;
}
public static final Role USER = new Role(0);
public static final Role APPROVER = new Role(1);
public static final Role EVENTADMIN = new Role(2);
public static final Role ADMIN = new Role(3);
public int toInt() {
return roleEnumID;
}
public static Role fromInt(int code) {
switch (code) {
case 0: return USER;
case 1: return APPROVER;
case 2: return EVENTADMIN;
case 3: return ADMIN;
default: throw new RuntimeException("Unknown User Role");
}
}
}
Here is the mapping doc.
<bag name="roles" table="user_roles" inverse="false" cascade="delete" >
<key column="USER_ID_FK"/>
<element type="com.matchboxsoftware.tickettout.domain.Role" column="ROLE_ENUM_ID"/>
</bag>