私のHQLコード:
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
このクエリは
Coloumn 1 | Column 2 | Column 3 | Column 4
3 | 2 | Product1 | ProductFilename1
2 | 1 | Product2 | ProductFilename2
それらをリストに入れて、jspページに表示したいと思います。
私の質問は次のとおりです。このクエリのカウントのためにフィールドをマップできるように、新しいクラスを作成する必要がありますか?何か助けてください?
私のクラスは次のとおりです。
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;
}
}
製品クラス:
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;
}
}
私は次のように拡張されたforループでリストを表示しようとしています:
<%
List<Object[]> myGadgets = new GadgetsRepository().getGadgetDescVotes();
for (Object p : myGadgets) {%>
<div class="gadgetItem">
<div><%=p[0]%> </div>//this don't work
</div>
<% }%>