title: Spring MVC + Thymeleaf - low performance on very large lists (20,000+ items)
body: <p>I'm working on a feature that has a dual list select box on the view layer. There are some 20,000 available items to be brought to the select and it is taking a very long time to load the page and every interaction (typing on a filter box, selecting item from the list, etc.) takes a very long time to process.</p>
  
  <p>Is there a way to speed it up?</p>
  
  <p>My form is:</p>
  
  <pre><code>&lt;form role="form" action="#" th:object="${pojo}" th:action="@{/contract/assignStructure}" method="post"&gt;
      &lt;select multiple="multiple" id="selectedStructures" name="selectedStructures" class="form-control"&gt;
          &lt;option th:each="structure : ${allStructures}" 
                  th:value="${structure.getId()}"
                  th:selected="${assignedStructures.contains(structure)}"
                  th:text="${structure.description}"&gt;
          &lt;/option&gt;
      &lt;/select&gt;
      &lt;br /&gt;
      &lt;div&gt;
          &lt;button type="submit" class="btn btn-primary" th:text="#{gen.save}"&gt;Save&lt;/button&gt;
      &lt;/div&gt;  
  &lt;/form&gt;
  </code></pre>
  
  <p>And the javascript section that handles this list is, so far:</p>
  
  <pre><code>$('#selectedStructures').bootstrapDualListbox();
  </code></pre>
  
  <p>The problem, I believe is in my Structure pojo whose attributes are defined as:</p>
  
  <pre><code>@Column(name = "description")
  private String description;
  
  @ManyToOne(fetch = FetchType.EAGER)
  @Cascade(org.hibernate.annotations.CascadeType.ALL)
  private Contract contract;
  
  @OneToMany(fetch = FetchType.LAZY)
  @Fetch(FetchMode.SELECT)
  @Cascade(org.hibernate.annotations.CascadeType.ALL)
  private List&lt;Term&gt; terms;
  </code></pre>
  
  <p>Possibly, the performance issue has to do with the <code>FetchType</code>.</p>
  
  <p>The business logic is that one or more <code>Structure</code> are part of a <code>Contract</code> and may have one or <code>Term</code>.</p>
  
  <p>Mapping on <code>Contract</code> is:</p>
  
  <pre><code>@OneToMany(fetch = FetchType.EAGER)
  @Fetch(FetchMode.SELECT)
  @Cascade(org.hibernate.annotations.CascadeType.ALL)
  private List&lt;Structure&gt; structures;
  </code></pre>
  
  <p>And mapping on <code>Term</code> is:</p>
  
  <pre><code>@ManyToOne(fetch = FetchType.EAGER)
  @Cascade(org.hibernate.annotations.CascadeType.ALL)
  private Structure structure;
  </code></pre>
  
  <p>Is this right? Is there a way to improve the performance of a method retrieving a <code>List&lt;Structure&gt; findAll()</code> by adjusting the annotations?</p>