title: Accessing multiple roles from database in spring boot security
body: <p>I have 3 tables USERS(has user details),ROLES(has roles' details),USER_ROLES(maps user_id to role_id). I want to retrieve roles of a user. When i imported them as entities ,my code looks like this:</p>
  
  <h2>User.java</h2>
  
  <pre><code>package com.eaiesb.entities;
  
  import java.io.Serializable;
  import javax.persistence.*;
  import java.math.BigDecimal;
  import java.util.List;
  
  
  /**
   * The persistent class for the USERS database table.
   * 
   */
  @Entity
  @Table(name="USERS")
  @NamedQuery(name="User.findAll", query="SELECT u FROM User u")
  public class User implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy=GenerationType.TABLE)
      @Column(name="USER_ID")
      private String userId;
  
      private String column1;
  
      private String column2;
  
      private String emailid;
  
      private String gender;
  
      private String name;
  
      private String password;
  
      private BigDecimal sno;
  
      private String status;
  
      //bi-directional many-to-many association to Role
      @ManyToMany
      @JoinTable(
          name="USER_ROLES"
          , joinColumns={
              @JoinColumn(name="USER_ID")
              }
          , inverseJoinColumns={
              @JoinColumn(name="ROLE_ID")
              }
          )
      private List&lt;Role&gt; roles;
  
      public User() {
      }
  
      public String getUserId() {
          return this.userId;
      }
  
      public void setUserId(String userId) {
          this.userId = userId;
      }
  
      public String getColumn1() {
          return this.column1;
      }
  
      public void setColumn1(String column1) {
          this.column1 = column1;
      }
  
      public String getColumn2() {
          return this.column2;
      }
  
      public void setColumn2(String column2) {
          this.column2 = column2;
      }
  
      public String getEmailid() {
          return this.emailid;
      }
  
      public void setEmailid(String emailid) {
          this.emailid = emailid;
      }
  
      public String getGender() {
          return this.gender;
      }
  
      public void setGender(String gender) {
          this.gender = gender;
      }
  
      public String getName() {
          return this.name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getPassword() {
          return this.password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public BigDecimal getSno() {
          return this.sno;
      }
  
      public void setSno(BigDecimal sno) {
          this.sno = sno;
      }
  
      public String getStatus() {
          return this.status;
      }
  
      public void setStatus(String status) {
          this.status = status;
      }
  
      public List&lt;Role&gt; getRoles() {
          return this.roles;
      }
  
      public void setRoles(List&lt;Role&gt; roles) {
          this.roles = roles;
      }
  
  }
  </code></pre>
  
  <p>"Role.java" looks similar too. I want to add roles of the user in getAuthoritites() of UserDetails, but am not able to, because it demands String but i can get roles only as List type.</p>
  
  <p>Tried casting to String with regular Java methods, but was of no help.</p>
  
  <p>Can anyone help?</p>