Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the <a href="http://download.oracle.com/javaee/5/tutorial/doc/bnbuf.html" rel="nofollow">Java EE tutorial</a> I read the following:</p> <blockquote> <p><strong>Return Types</strong></p> <p>The return type of the SELECT clause is defined by the result types of the select expressions contained within it. If multiple expressions are used, the result of the query is an Object[], and the elements in the array correspond to the order of the expressions in the SELECT clause, and in type to the result types of each expression.</p> </blockquote> <p>Now your query looks like:</p> <pre><code>SELECT g.filename, g.description, g.uploadDate FROM Garbage g; </code></pre> <p>From your entity class <code>Garbage</code> I read that <code>filename</code>, <code>description</code>, <code>uploadDate</code> are Strings. Then your query returns a list of <code>Object[]</code> and each array element contains a String and not a <code>Garbage</code> object.</p> <p>If your array contains Strings and not Garbage, you cannot call <code>garbage[0].filename</code> in your facelet.</p> <p>Try to change your Query in the following way:</p> <pre><code>SELECT g FROM Garbage g; </code></pre> <p>Then you get a <code>List&lt;Garbage&gt;</code>. In the <code>SearchEJB</code> change the method signature to the following:</p> <pre><code>public List&lt;Garbage&gt; findAllGarbage() </code></pre> <p>Change the methods in your <code>ResultsController</code> managed bean accordingly (now you always need a <code>List&lt;Garbage&gt;</code> and not a <code>List&lt;Garbage[]&gt;</code>).</p> <p>Finally modify your <code>p:dataTable</code> (shown for the first column):</p> <pre><code>&lt;p:column sortBy="#{garbage.filename}"&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; </code></pre> <p><strong>UPDATE:</strong></p> <p>If you want to keep your query you could convert the <code>Object[]</code> into a list of <code>Garbage</code> objects and leave the missing fields empty. Something like this (add a constructor to your Garbage class):</p> <pre><code>List&lt;Garbage&gt; gList = new ArrayList(); for (Object[] o: query.getResultList()) { gList.add(new Garbage(o[0], o[1], o[2]); } </code></pre> <p><strong>UPDATE 2:</strong></p> <p>In your update you missed again, that your array contains strings. And the strings are ordered as your select expression is ordered: element 0: filename, element 1: description, element 2: uploadDate.</p> <p>Change your loop in the following way:</p> <pre><code>for (Object o: query.getResultList()) { Garbage tmpG = new Garbage(); tmpG.setFilename(o[0]); tmpG.setDescription(o[1]); tmpG.setUploadDate(o[2]); gList.add(tmpG); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload