We're mapping Users to Roles (with Roles being an Enum). Our stack includes JPA, Hibernate Envers and we use JBoss Developer Studio.
Challenge is that the @ElementCollection creates weird errors (randomly claiming @Entity name is empty, generator for IDs isn't defined, etc.) in almost all model objects. Commenting out @ElementCollection everything compiles fine, but the application won't run. This was created (and in theory working) by a developer currently on vacation (so I can't verify it WAS actually working after it was checked in). According to the JPA/Hibernate documentation, this "looks" like it should work.
We've been looking at this for hours. Anyone have any hunches, thoughts, or ideas?
Code:
// User includes this field:
@NotAudited
@ElementCollection(targetClass=Roles.class)
@Enumerated(EnumType.STRING)
@CollectionTable(
name="USER_ROLES",
joinColumns=
@JoinColumn(
name="USER_ID",
referencedColumnName="ID"
)
)
@Column(name="ROLE")
private Set<Roles> roles;
public enum Roles {
//J-
DEVELOPER ("Developer", "Developers of the application", true),
VIEW ("View", "Users authorized to search and view throughout the system", true),
EDIT ("Edit", "Users authorized to edit throughout the system", true),
GLOBAL ("Global", "Any authenticated user is allowed to do this action.", true),
UNAUTHENTICATED ("Unauthenticated", "Any person is allowed to do this action.", true);
//J+
private String roleName;
private String description;
private boolean internalRole;
public static List<Roles> getInternalRoles() {
List<Roles> roles = new ArrayList<Roles>();
for (Roles role : values()) {
if (role.isInternalRole()) {
roles.add(role);
}
}
roles.remove(GLOBAL);
roles.remove(UNAUTHENTICATED);
return roles;
}
// DATABASE
USERS
ID
...
USER_ROLES
USER_ID
ROLE