jpa - Using COUNT in JPQL Query -
i have following jpql query:
list<destinationinfo> destinations = em.createquery("select new com.realdolmen.patuva.dto.destinationinfo(d.name, d.continent, min(t.departuredate), min(t.priceperday), count(t.id))" + " destination d, trip t" + " d.continent = :continent " + " group d.name, d.continent").setparameter("continent", searchedcontinent).getresultlist();
if run error:
javax.ejb.ejbtransactionrolledbackexception: org.hibernate.hql.internal.ast.querysyntaxexception: unable locate appropriate constructor on class [com.realdolmen.patuva.dto.destinationslist]
if leave out count(t.id)
, remove parameter destinationinfo
constructor works fine. why can't map count(t.id)
destinationinfo
dto.
this destinationinfo
class:
public class destinationinfo { private string name; private continent continent; private date earliestdeparture; private integer totalnumtrips; private bigdecimal lowestprice; public destinationinfo(string name, continent continent, date earliestdeparture, bigdecimal lowestprice, integer totalnumtrips) { this.name = name; this.continent = continent; this.earliestdeparture = earliestdeparture; this.totalnumtrips = totalnumtrips; this.lowestprice = lowestprice; } // getters , setters }
apparently count(t.id)
returns number of type long
. changing destinationinfo
class following makes work:
public class destinationinfo { private string name; private continent continent; private date earliestdeparture; private long totalnumtrips; private bigdecimal lowestprice; public destinationinfo(string name, continent continent, date earliestdeparture, bigdecimal lowestprice, long totalnumtrips) { this.name = name; this.continent = continent; this.earliestdeparture = earliestdeparture; this.totalnumtrips = totalnumtrips; this.lowestprice = lowestprice; } // getters , setters }
Comments
Post a Comment