Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Hibernate select count with other columns
    text
    copied!<p>My HQL code:</p> <pre><code> select count(products.id) ,products.id, products.productDescription, p.products.productFileName from Polls as p group by products.id order by count(products.id) desc </code></pre> <p>This query returns </p> <pre><code> Coloumn 1 | Column 2 | Column 3 | Column 4 3 | 2 | Product1 | ProductFilename1 2 | 1 | Product2 | ProductFilename2 </code></pre> <p>I wish to put them in a list then display them in jsp page.</p> <p><strong>My question is</strong>: do I need to create new class so I can map the fields because of the count just for this query? Any help please?</p> <p>my classes are:</p> <pre><code> public class Polls implements java.io.Serializable { private Integer id; private Products products; private Users users; private Date voteDate; public Polls() { } public Polls(Products products, Users users, Date voteDate) { this.products = products; this.users = users; this.voteDate = voteDate; } public Integer getId() { return this.id; } public void setId(Integer id) { this.id = id; } public Products getProducts() { return this.products; } public void setProducts(Products products) { this.products = products; } public Users getUsers() { return this.users; } public void setUsers(Users users) { this.users = users; } public Date getVoteDate() { return this.voteDate; } public void setVoteDate(Date voteDate) { this.voteDate = voteDate; } </code></pre> <p>}</p> <p>Product class:</p> <pre><code> public class Products implements java.io.Serializable { private Integer id; private String productDescription; private String productFileName; private Set pollses = new HashSet(0); public Products() { } public Products(String productDescription) { this.productDescription = productDescription; } public Products(String productDescription, String productFileName, Set pollses) { this.productDescription = productDescription; this.productFileName = productFileName; this.pollses = pollses; } public Integer getId() { return this.id; } public void setId(Integer id) { this.id = id; } public String getProductDescription() { return this.productDescription; } public void setProductDescription(String productDescription) { this.productDescription = productDescription; } public String getProductFileName() { return this.productFileName; } public void setProductFileName(String productFileName) { this.productFileName = productFileName; } public Set getPollses() { return this.pollses; } public void setPollses(Set pollses) { this.pollses = pollses; } </code></pre> <p>}</p> <p>I'm trying to display the list with an enhanced for loop like this:</p> <pre><code> &lt;% List&lt;Object[]&gt; myGadgets = new GadgetsRepository().getGadgetDescVotes(); for (Object p : myGadgets) {%&gt; &lt;div class="gadgetItem"&gt; &lt;div&gt;&lt;%=p[0]%&gt;&amp;nbsp;&lt;/div&gt;//this don't work &lt;/div&gt; &lt;% }%&gt; </code></pre>
 

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