Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Advice request for storing a List of Enum values

Hi, I am looking for implementation tips for storing a List of Enum values.

I have been reading the
http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg00915.html
thread, it gives me some options but I'm not sure what path to take. I
will try to explain my model first and then I list a number of
concerns I have.

I want to have a model like:

User --* Role *-- Action


public class User {
    private List<Role > roles;

    public List<Role > getRoles() {
        return roles;
    }

    public void setRoles(List<Role > value) {
        this.roles= value;
    }
}

public class Action {
    private List<Role > roles;

    public List<Role > getRoles() {
        return roles;
    }

    public void setRoles(List<Role > value) {
        this.roles= value;
    }
}

public enum Role {
    admin,
    user
}

I want the database to look like:

Table User
- Column id

Table Action
- Column id

Table User_Role
- Column userId
- Column roleId

Table Action_Role
- Column actionId
- Column roleId

Table Role
- Column id (Enum string value, primary key)


- The Role table will be manually filled with 2 rows: 'admin' and
'user' when the database is created.
- The User_Role and Action_Role will have foreign key constrains to
the relevant tables.
- With this approach I ensure database integrity.

Should I use a BasicCollection (like the advice given here:
http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg00917.html)
the way to go? If so, is there somewhere an example which uses Enums?
Or do I need to fall back on a Class mapping, which is portable to
other JPA implementations, but requires me to convert class values to
java enums?

Thank you,

Martijn


Back to the top