title: dataTable sortBy function does not work(primefaces)
body: <p>I have a problem with the primefaces dataTable component. I dont know why it does not short the data in the table when i click on it. </p>
  
  <pre><code>&lt;p:dataTable var="garbage" value="#{resultsController.allGarbage}" dynamic="true" paginator="true" paginatorPosition="bottom" rows="10"  
               paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
               rowsPerPageTemplate="5,10,15"&gt;         
  
              &lt;p:column sortBy="#{garbage[0].filename}"&gt;  
              &lt;f:facet name="header"&gt;  
              &lt;h:outputText value="Filename" /&gt;  
              &lt;/f:facet&gt;  
              &lt;h:outputText value="#{garbage[0]}" /&gt;
               &lt;/p:column&gt; 
  
              &lt;p:column&gt;  
              &lt;f:facet name="header"&gt;  
              &lt;h:outputText value="Description" /&gt;  
              &lt;/f:facet&gt;  
              &lt;h:outputText value="#{garbage[1]}" /&gt;  
               &lt;/p:column&gt; 
  
              &lt;p:column sortBy="#{garbage[2].uploadDate}"&gt;  
              &lt;f:facet name="header"&gt;  
              &lt;h:outputText value="Upload date" /&gt;  
              &lt;/f:facet&gt;  
              &lt;h:outputText value="#{garbage[2]}" /&gt; 
               &lt;/p:column&gt;                
      &lt;/p:dataTable&gt; 
  </code></pre>
  
  <p>This is the managed bean</p>
  
  <pre><code>@ManagedBean
  @RequestScoped
  public class ResultsController {
  
  @EJB
  private ISearchEJB searchEJB;
  
  private Garbage[] garbage;
  
  public List&lt;Garbage[]&gt; getAllGarbage() {
      return searchEJB.findAllGarbage();
  }
  
  public Garbage[] getGarbage() {
      System.out.println("VALUES!!!!!!!!" + garbage[0].getFilename());
      return garbage;
  }
  
  public void setGarbage(Garbage[] garbage) {
      this.garbage = garbage;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is the EJB that allows data access</p>
  
  <pre><code>@Stateless(name = "ejbs/SearchEJB")
  </code></pre>
  
  <p>public class SearchEJB implements ISearchEJB {</p>
  
  <pre><code>@PersistenceContext
  private EntityManager em;
  
  
  public List&lt;Garbage[]&gt; findAllGarbage() {
      Query query = em.createNamedQuery("findAllGarbage");        
      return  query.getResultList();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And this is the entity(Data representation)</p>
  
  <pre><code>@NamedQuery(name = "findAllGarbage", query = "SELECT g.filename, g.description,  g.uploadDate FROM Garbage g;")
      @Entity
      public class Garbage {
  @Id
  @GeneratedValue
  @Column(nullable = false)
  private Long id;
  @Column(nullable = false)
  private String filename;
  @Column(nullable = false)
  private String fileType;
  @Column(nullable = false)
  private String uploadDate;
  @Column(nullable = false)
  private String destroyDate;
  @Lob
  @Column(nullable = false)
  private byte[] file;
  @Column(nullable = false)
  private String description;
  ...//Getters and Setters
  </code></pre>
  
  <p>As shown in the image there is no changes when the sort buttons are clicked:
  <img src="https://i.stack.imgur.com/dDsir.png" alt="enter image description here"></p>
  
  <p>This is what the console says:</p>
  
  <blockquote>
    <p>SEVERE: Error in sorting</p>
  </blockquote>
  
  <p><b>UPDATE</b></p>
  
  <pre><code>public List&lt;Garbage&gt; findAllGarbage() {
      Query query = em.createNamedQuery("findAllGarbage");    
  
      List&lt;Garbage&gt; gList = new ArrayList();
  
      for (Object o: query.getResultList()) {         
        Garbage tmpG = new Garbage();
        tmpG.setFilename(((Garbage) o).getFilename());          
        tmpG.setUploadDate(((Garbage) o).getUploadDate());
        tmpG.setDescription(((Garbage) o).getDescription());
  
        gList.add(tmpG);
      }
      return  gList;
  }
  </code></pre>
  
  <p>The modified managed bean</p>
  
  <pre><code>@ManagedBean
  @RequestScoped
  public class ResultsController {
  
  @EJB
  private ISearchEJB searchEJB;
  
  private Garbage garbage;
  
  public List&lt;Garbage&gt; getAllGarbage() {
      return searchEJB.findAllGarbage();
  }
  
  public Garbage getGarbage() {
      return garbage;
  }
  
  public void setGarbage(Garbage garbage) {
      this.garbage = garbage;
  }   
  </code></pre>
  
  <p>}</p>
  
  <p>The modified JSF</p>
  
  <pre><code>&lt;p:dataTable var="garbage" value="#{resultsController.allGarbage}" dynamic="true" paginator="true" paginatorPosition="bottom" rows="10"  
               paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
               rowsPerPageTemplate="5,10,15"&gt;         
  
              &lt;p:column sortBy="#{garbage.filename}" parser="string"&gt;  
              &lt;f:facet name="header"&gt;  
              &lt;h:outputText value="Filename" /&gt;  
              &lt;/f:facet&gt;  
              &lt;h:outputText value="#{garbage.filename}" /&gt;
               &lt;/p:column&gt; 
  
              &lt;p:column&gt;  
              &lt;f:facet name="header"&gt;  
              &lt;h:outputText value="Description" /&gt;  
              &lt;/f:facet&gt;  
              &lt;h:outputText value="#{garbage.description}" /&gt;  
               &lt;/p:column&gt; 
  
              &lt;p:column sortBy="#{garbage.uploadDate}" parser="string"&gt;  
              &lt;f:facet name="header"&gt;  
              &lt;h:outputText value="Upload date" /&gt;  
              &lt;/f:facet&gt;  
              &lt;h:outputText value="#{garbage.uploadDate}" /&gt; 
               &lt;/p:column&gt;                
      &lt;/p:dataTable&gt; 
  </code></pre>