title: Need help on Java, JPA, Thymeleaf and Mysql
body: <p>I'm new on this site and new in coding. I am struggling to link the two by referencing Competition to User, and retrieve the data from the database (I'm using Mysql Workbench). It's connected but I can't make it work on my localhost (gave me the Whitelabel Error Page). It could be my code or template that needs correcting.</p>
  
  <pre><code>@Entity
  public class Competition {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;
      private String title;
      private String description;
  
      @OneToMany(mappedBy = "competition", targetEntity = User.class)
      private List&lt;User&gt; users;
  
      public Competition() {}
  
      public Competition(Integer id, String title, String description) {
          this.id = id;
          this.title = title;
          this.description = description;
      }
  
      public Integer getId() {
          return id;
      }
  
      public String getTitle() {
          return title;
      }
  
      public String getDescription() {
          return description;
      }
  
      public List&lt;User&gt; getUsers() {
          return users;
      }
  }
  </code></pre>
  
  
  
  <pre><code>@Entity
  public class User {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id_User;
      private String name;
      private String role;
  
      @ManyToOne(fetch=FetchType.LAZY)
      @JoinColumn(name = "id")
      private Competition competition;
  
      public User() {}
  
      public User(Integer id_User, String name, String role) {
          this.id_User = id_User;
          this.name = name;
          this.role = role;
      }
  
      public Integer getId_User() {
          return id_User;
      }
  
      public String getName() {
          return name;
      }
  
      public String getRole() {
          return role;
      }
  
      public Competition getCompetition() {
          return competition;
      }
  }
  </code></pre>
  
  
  
  <pre><code>public class CompetitionService {
  
      @Autowired
      CompetitionRepository competitionRepository;
  
      public List&lt;Competition&gt; getAllCompetitions() {
          List&lt;Competition&gt; competitions = new ArrayList&lt;&gt;();
          competitionRepository.findAll().forEach(competitions :: add);
          return competitions;
      }
  }
  </code></pre>
  
  
  
  <pre><code>public class UserService {
  
      @Autowired
      private UserRepository userRepository;
  
      public List&lt;User&gt; getAllUsers() {
          List&lt;User&gt; users = new ArrayList&lt;&gt;();
          userRepository.findAll().forEach(users :: add);
          return users;
      }
  }
  </code></pre>
  
  
  
  <pre><code>public interface CompetitionRepository extends CrudRepository&lt;Competition, Integer&gt; {
      public List&lt;Competition&gt; getAllCompetitions();
  }​
  </code></pre>
  
  
  
  <pre><code>public interface UserRepository extends CrudRepository&lt;User, Integer&gt;{}​
  </code></pre>
  
  
  
  <pre><code>@Controller
  public class CompetitionController {
  
      @Autowired
      private CompetitionService competitionService;
  
      @RequestMapping(value = "/list", method = RequestMethod.GET)
      public String competitionListing(Model model) {
          model.addAttribute("competitions", competitionService.getAllCompetitions());
          return "list";
      }
  }
  </code></pre>
  
  
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en" xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"/&gt;
      &lt;title&gt;List of Competitions&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Short Competitions&lt;/h1&gt;
  
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Competition Title&lt;/th&gt;
          &lt;th&gt;Description&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr th:each="competition : ${competitions}"&gt;
          &lt;td&gt;
              &lt;a th:href="@{'/competition/' + ${competition.id}}"
                 th:text="${competition.title}"&gt;Competition Title&lt;/a&gt;
          &lt;/td&gt;
          &lt;td th:text="${competition.description}"&gt;Competition Description&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>