2013-10-07 3 views
1

je la requête JPQL suivante:des numérations dans JPQL la requête

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))" + 
      " FROM Destination d, Trip t" + 
      " WHERE d.continent = :continent " + 
      " GROUP BY d.name, d.continent").setParameter("continent", searchedContinent).getResultList(); 

Si je cours ce que j'obtiens l'erreur:

javax.ejb.EJBTransactionRolledbackException: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.realdolmen.patuva.dto.DestinationsList] 

Si je quitte le COUNT(t.id) et supprimer ce paramètre de mon DestinationInfo constructeur ça fonctionne bien. Pourquoi ne puis-je pas mapper le COUNT(t.id) sur mon DTO DestinationInfo?

Ceci est ma DestinationInfo classe:

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 and setters 
} 
+0

@AndreiI Eh oui, je l'avais comme 'l'origine int' réellement puis changé pour' Integer' pour voir si cela fonctionnerait – Mekswoll

Répondre

2

Apparemment COUNT(t.id) retourne un certain nombre de type long. Modification de la classe DestinationInfo à ce qui suit fait fonctionner:

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 and setters 
}