by vreimz 21 May 17:31
Enum mapping

I class User with fields username and List roles etc and
public enum SecurityRole {
ROLE_ADMIN, etc
}

In database are 2 tables: user (id, username, etc) and role (user_id, role)

(many-to-one realation between User and SecurityRole)

Is there any way to map list of enums that way with Ebeans?

21 May 22:18
by Rob

If you mean you want to have a List of Enums in your java bean... then no, that is not supported.

If I missed your point then can you explain a bit more what your problem is... I assume you are mapping the enum SecurityRole to the role column of the role table?

22 May 04:20
by vreimz

Yes, I have two things in my application:

public class User {
private String username;
private List roles
//getters and setters
}

and

public enum SecurityRole {
ROLE_ADMIN, ROLE_MODERATOR, ROLE_NONE;
}

And, yes, I want to map SecurityRole to the role column of the role table.

22 May 04:33
by vreimz

p.s. List in class User is list of SecurityRoles

23 May 03:17
by Rob
...
private List<SecurityRole> roles;

At the moment this is not supported. That is, the entries in the list have to be a @Entity ... rather than a enum/scalar/embedded bean.

In your case it is a List of enum... but the same applies for "scalar values" (String, Integer, Double, Timestamp etc) ... and also for Embedded beans.

NOTE: I believe JPA 2.0 will contain support for this type of mapping.

I'll log this as an enhancement request.

Cheers, Rob.

23 May 03:23
by Rob

Create a New Topic

Title:
Body:
 
Introduction User Guide (pdf) Install/Configure Public JavaDoc Whitepapers
General Database Specific Byte Code Deployment Annotations Features
Top Bugs Top Enhancements
woResponse