1

次の JPQL クエリがあります。

    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();

これを実行すると、次のエラーが表示されます。

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

を省略してコンストラクターCOUNT(t.id)からそのパラメーターを削除すると、正常に機能します。をDTODestinationInfoにマップできないのはなぜですか。COUNT(t.id)DestinationInfo

これは私のDestinationInfoクラスです:

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
}
4

1 に答える 1

2

どうやらCOUNT(t.id)type の数を返しますlongDestinationInfoクラスを次のように変更すると、機能します。

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
}
于 2013-10-07T14:12:54.063 に答える