title: An issue with getting user roles in a Spring Rest application
body: <p>I have a RestController class with the following :</p>
  
  <pre><code>@RestController
  public class UserRestController 
  {
  @Autowired
  UserService userService;
  
  @Autowired
  private SecurityService securityService;
  
  @Autowired
  private UserValidator userValidator;
  
  // Get a Single User
  @GetMapping("/api/users/{id}")
  public User getUserById(@PathVariable(value = "id") Long userId) {
      return userService.getUserById(userId);
  }
  </code></pre>
  
  <p>This is getUserById function in UserService :</p>
  
  <pre><code> public User getUserById(@PathVariable(value = "id") Long userId) {
      return userRepository.findById(userId).orElseThrow(() -&gt; new ResourceNotFoundException("User", "id", userId));
  }
  </code></pre>
  
  <p>This is the result of a GET request on <strong>localhost:8080/api/users/11</strong> :</p>
  
  <pre><code>{
  "id": 11,
  "name": null,
  "email": null,
  "password": "$2a$10$HykDWcHU3vO9YAcdXiWieua9YyYMkwrNIk7WgpmVzVwENb71fDCsW",
  "status": null,
  "tel": null,
  "confirmation": null,
  "birth_date": null,
  "createdAt": "2018-05-22T09:09:12.000+0000",
  "updatedAt": "2018-05-22T09:09:12.000+0000",
  "username": "ouissal@gmail.com"
  }
  </code></pre>
  
  <p>This is the result of a GET request on <strong>localhost:8080/users/11</strong></p>
  
  <pre><code>{
  "name": null,
  "email": null,
  "password": "$2a$10$HykDWcHU3vO9YAcdXiWieua9YyYMkwrNIk7WgpmVzVwENb71fDCsW",
  "status": null,
  "tel": null,
  "confirmation": null,
  "birth_date": null,
  "createdAt": "2018-05-22T09:09:12.000+0000",
  "updatedAt": "2018-05-22T09:09:12.000+0000",
  "username": "ouissal@gmail.com",
  "_links": {
      "self": {
          "href": "http://localhost:8080/users/11"
      },
      "user": {
          "href": "http://localhost:8080/users/11"
      },
      "roles": {
          "href": "http://localhost:8080/users/11/roles"
      }
  }
  }
  </code></pre>
  
  <p>I do not have anything mapped for /users in my controller, how can I get the roles using my controller? </p>
  
  <hr>
  
  <h2>edit</h2>
  
  <p>This is my User class :</p>
  
  <pre><code>@Entity
  @Table(name = "user")
  @EntityListeners(AuditingEntityListener.class)
  @JsonIgnoreProperties(value = {"createdAt", "updatedAt"}, 
      allowGetters = true)
  </code></pre>
  
  <p>public class User implements Serializable{</p>
  
  <pre><code>private static final long serialVersionUID = 1L;
  
  
  public User() {
      super();
      // TODO Auto-generated constructor stub
  }
  
  @Id
  @Column(name = "user_id")
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private long id;
  
  @Column(name = "user_name")
  //@NotBlank
  private String name;
  
  @Column(name = "user_email")
  //@NotBlank
  private String email;
  
  @Column(name = "user_password")
  @NotBlank
  private String password;
  
  @Column(name = "user_status")
  private String status;
  
  @Column(name = "user_tel")
  private String tel;
  
  @Column(name = "user_confirmation")
  private String confirmation;
  
  @Column(name = "user_birth_date")
  @Temporal(TemporalType.DATE)
  private Date birth_date;
  
  @Column(nullable = false, updatable = false)
  @Temporal(TemporalType.TIMESTAMP)
  @CreatedDate
  private Date createdAt;
  
  @Column(nullable = false)
  @Temporal(TemporalType.TIMESTAMP)
  @LastModifiedDate
  private Date updatedAt;
  
  @JsonBackReference
  @ManyToMany
  @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
  private Set&lt;Role&gt; roles;
  
  @Column(name = "username")
  @NotBlank
  private String username;
  
  public long getId() {
      return id;
  }
  
  public void setId(long id) {
      this.id = id;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getUsername() {
      return username;
  }
  
  public void setUsername(String username) {
      this.username = username;
  }
  
  public String getEmail() {
      return email;
  }
  
  public void setEmail(String email) {
      this.email = email;
  }
  
  public String getPassword() {
      return password;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  
  public String getStatus() {
      return status;
  }
  
  public void setStatus(String status) {
      this.status = status;
  }
  
  public String getTel() {
      return tel;
  }
  
  public void setTel(String tel) {
      this.tel = tel;
  }
  
  public String getConfirmation() {
      return confirmation;
  }
  
  public void setConfirmation(String confirmation) {
      this.confirmation = confirmation;
  }
  
  public Date getBirth_date() {
      return birth_date;
  }
  
  public void setBirth_date(Date birth_date) {
      this.birth_date = birth_date;
  }
  
  public Date getCreatedAt() {
      return createdAt;
  }
  
  public Date getUpdatedAt() {
      return updatedAt;
  }
  
  public void setUpdatedAt(Date updatedAt) {
      this.updatedAt = updatedAt;
  }
  
  public Set&lt;Role&gt; getRoles() {
      return roles;
  }
  
  public void setRoles(Set&lt;Role&gt; roles) {
      this.roles = roles;
  }
  }
  </code></pre>
  
  <p>and this is my role class :</p>
  
  <pre><code>@Entity
  @Table(name = "role")
  public class Role {
  
  @Id
  @Column(name = "role_id")
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  @Column(name = "role_name")
  private String name;
  @ManyToMany(mappedBy = "roles")
  @JsonManagedReference
  private Set&lt;User&gt; users;
  
  
  
  public Role() {
      super();
  }
  
  public Long getId() {
      return id;
  }
  
  public void setId(Long id) {
      this.id = id;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  
  public Set&lt;User&gt; getUsers() {
      return users;
  }
  
  public void setUsers(Set&lt;User&gt; users) {
      this.users = users;
  }
  }
  </code></pre>