1 Reply Latest reply on Mar 14, 2009 3:50 AM by trouby

    Access of additional attributes in join tables

    maurice.mdrueke.gmx.de
      Hi all,
      I am new to seam. Currently I am trying to develop an user authorization that is based on three different database tables:

      USER (User information: user_id, name, ...)
      ROLE (Role information: role_id, name)
      USER_ROLE (Foreign Key to user_id, Foreign Key to role_id, Valid_from, valid_until)

      I used seam-gen to build a CRUD application.

      My question is: How can I access attributes of the USER_ROLE table. The table is used as join table in the User entity.
      Here is some code of the User class:

      @Entity
      @Table(name = "USER")
      public class User implements java.io.Serializable {

           @Id
           @GeneratedValue(strategy = IDENTITY)
           @Column(name = "ID", unique = true, nullable = false)
           private Integer id;

           @Column(name = "USERNAME", nullable = false, length = 25)
           @NotNull
           @Length(max = 25)     
           private String username;

           @Column(name = "PASSWORD", nullable = false)
           @NotNull
           private String password;
           
           @Column(name = "EMAIL", nullable = false)
           @NotNull
           private String email;
           
           @UserRoles
              @OneToMany(fetch = FetchType.LAZY, targetEntity=Role.class)
              @JoinTable(
              name = "USER_ROLE",
              joinColumns = @JoinColumn(name = "USER_ID", referencedColumnName="ID"),
              inverseJoinColumns = @JoinColumn(name = "ROLE_ID", referencedColumnName="ID")
          )
           private Set<Role> roles = new HashSet<Role>(0);

           public User() {
           }

           public User(String username, String password, String email) {
                this.username = username;
                this.password = password;
                this.email = email;
           }
           public User(String username, String password, String email,
                     Set<Role> roles) {
                this.username = username;
                this.password = password;
                this.email = email;
                this.roles = roles;
           }

           
           public Integer getId() {
                return this.id;
           }

           public void setId(Integer id) {
                this.id = id;
           }


           public String getUsername() {
                return this.username;
           }

           public void setUsername(String username) {
                this.username = username;
           }


           public String getPassword() {
                return this.password;
           }

           public void setPassword(String password) {
                this.password = password;
           }


           public String getEmail() {
                return this.email;
           }

           public void setEmail(String email) {
                this.email = email;
           }

           public Set<Role> getRoles() {
                return this.roles;
           }

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

      }

      Best Regards

      Maurice