I'm trying to create a many-to-many relationship between two types of which one is an Enumerated type. Lets say the first model is User and the second model is Role. A user can have many roles and a role can belong to many users.
I'd like to be able to write simple code like:
if (user.getRoles().contains(Role.ADMIN)) {
//do something
}
Does anyone know if this is possible? I've seen that there is an @Enumerated Hibernate annotation but this doesn't look to be of use to me.
I've currently implemented a solution by created a model for a link table but this is very messy. Any help much appreciated.
-gearoid
UPDATE: Can someone specify how to persist an EnumSet on a model? The info above still stands, I wish to create a ManyToMany relationship with an Enumerated Type.