-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: ElementCollection with Enum
PostPosted: Tue Feb 24, 2015 5:53 pm 
Newbie

Joined: Thu Mar 06, 2014 4:09 pm
Posts: 3
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


Top
 Profile  
 
 Post subject: Re: ElementCollection with Enum
PostPosted: Wed Feb 25, 2015 11:01 am 
Newbie

Joined: Thu Mar 06, 2014 4:09 pm
Posts: 3
The random Entity error thing is a known bug:

https://issues.jboss.org/browse/JBIDE-16016

Please consider voting this up - the only way to get it working today is disable JPA validation.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.