title: Can't reach the object from thymeleaf
body: <p>I have a simple project with spring boot/thymeleaf and i have this problem about accessing an object from thymeleaf.
   I have my user and role objects. Here is my User entity:</p>
  
  <pre><code>@Entity
  @Table(name = "users")
  public class User {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int id;
      @Column(unique = true)
      private String username;
      private String password;
      private int enabled;
      @ManyToOne
      private Role role;
  
      // getters and setters...
  
  }
  </code></pre>
  
  <p>and Role entity:</p>
  
  <pre><code>@Entity
  @Table(name = "roles")
  public class Role {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int id;
      private String role;
  
      // getters and setters...
  }
  </code></pre>
  
  <p>controller that i'm providing objects:</p>
  
  <pre><code>@RequestMapping(value = "edit", method = RequestMethod.GET)
  public ModelAndView editRoles(){
      ModelAndView modelAndView= new ModelAndView();
      modelAndView.addObject("users", userService.getAll());
      modelAndView.addObject("roles", roleService.getAll());
      modelAndView.setViewName("editRole");
      System.out.println(userService.findUser(2).getRole().getRole());
      return modelAndView;
  }
  </code></pre>
  
  <p>on the page, im trying to edit users roles with a select box. and i want it to show the users role as selected value. but it doesnt work. Here is that code:</p>
  
  <pre><code>&lt;tr th:each="user : ${users}"&gt;
      &lt;td &gt;
          &lt;select class="form-control" id="sel1" th:field="*{roles}" &gt;
              &lt;option th:each="role : ${roles}" th:value="${role.id}" th:text="${role.role}" th:selected="${user.role.role}"&gt;
              &lt;/option&gt;
          &lt;/select&gt;
      &lt;/td&gt; 
  &lt;/tr&gt;
  </code></pre>
  
  <p>the problem is about that user.role.role part. It gives </p>
  
  <blockquote>
    <p>SpringEL expression</p>
  </blockquote>
  
  <p>error.    </p>
  
  <p>When i use <code>user.role</code>, i can access the role object; but i can't use role's attributes. 
  And the funny part is when i use completely different entities with exactly same configurations, i'm not getting any errors.</p>
  
  <p>Can anybody tell me what's the problem here?</p>