错误:org.hibernate.PropertyNotFoundException:类中没有合适的构造函数:com.a.offering.dto.SellerDetailsDto

时间:2012-06-06 06:49:39

标签: java spring hibernate orm

我正在使用以下查询 String queryString =“select new com.h.offering.dto.SellerDetailsDto(p.productId,p.sellerId,p.sellerSku,p.sellPrice,”+                 “p.transferPrice,p.sellerMRP,p.aCommission,p.baseShippingFee,p.addnShippingFee,”+                 “p.propogationLevel,p.propogationValue,a.warehouseName,a.quantity,a.maxShippingTime,a.minShippingTime)”                 +“来自PriceDetails p,AvailabilityDetails a”                 +“其中a.productId = p.productId”                 +“和a.sellerSku = p.sellerSku”                 +“和a.sellerId =:sellerId”;

执行时我收到错误

org.hibernate.hql.ast.QuerySyntaxException:无法在类[com.a.offering.dto.SellerDetailsDto]上找到合适的构造函数[从com中选择新的com.s.ofofing.dto.SellerDetailsDto(p.productId) .a.offering.db.domain.PriceDetails p,com.a.offering.db.domain.AvailabilityDetails a a.productId = p.productId和a.sellerSku = p.sellerSku and a.sellerId =:sellerId]     在org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)     在org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)     在org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)     在org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)     在org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)     在org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)

依旧......

我无法弄清楚错误。帮帮我

The code for SellerDetailsDto.java is 

package com.a.offering.dto;
public class SellerDetailsDto {
    public String productId;
    public String sellerId;
    public String sellerSku;
    public Double sellPrice;
    public Double transferPrice;
    public Double sellerMRP;
    public Double a;
    public Double baseShippingFee;
    public Double addnShippingFee;
    public String propogationLevel;
    public String propogationValue;
    public String warehouseName;
    public int quantity;
    public int maxShippingTime;
    public int minShippingTime;

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getSellerId() {
        return sellerId;
    }

    public void setSellerId(String sellerId) {
        this.sellerId = sellerId;
    }

    public String getSellerSku() {
        return sellerSku;
    }

    public void setSellerSku(String sellerSku) {
        this.sellerSku = sellerSku;
    }

    public String getWarehouseName() {
        return warehouseName;
    }

    public void setWarehouseName(String warehouseName) {
        this.warehouseName = warehouseName;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public int getMaxShippingTime() {
        return maxShippingTime;
    }

    public void setMaxShippingTime(int maxShippingTime) {
        this.maxShippingTime = maxShippingTime;
    }

    public int getMinShippingTime() {
        return minShippingTime;
    }

    public void setMinShippingTime(int minShippingTime) {
        this.minShippingTime = minShippingTime;
    }

    public Double getSellPrice() {
        return sellPrice;
    }

    public void setSellPrice(Double sellPrice) {
        this.sellPrice = sellPrice;
    }

    public Double getTransferPrice() {
        return transferPrice;
    }

    public void setTransferPrice(Double transferPrice) {
        this.transferPrice = transferPrice;
    }

    public Double getSellerMRP() {
        return sellerMRP;
    }

    public void setSellerMRP(Double sellerMRP) {
        this.sellerMRP = sellerMRP;
    }

    public Double a() {
        return a;
    }

    public void a(Double aa) {

a}

    public Double getBaseShippingFee() {
        return baseShippingFee;
    }

    public void setBaseShippingFee(Double baseShippingFee) {
        this.baseShippingFee = baseShippingFee;
    }

    public Double getAddnShippingFee() {
        return addnShippingFee;
    }

    public void setAddnShippingFee(Double addnShippingFee) {
        this.addnShippingFee = addnShippingFee;
    }

    public String getPropogationLevel() {
        return propogationLevel;
    }

    public void setPropogationLevel(String propogationLevel) {
        this.propogationLevel = propogationLevel;
    }

    public String getPropogationValue() {
        return propogationValue;
    }

    public void setPropogationValue(String propogationValue) {
        this.propogationValue = propogationValue;
    }

}

2 个答案:

答案 0 :(得分:3)

Hibernate需要一个至少包私有(即默认)可见性的构造函数。

通常情况下,无参数构造函数是必需的(您隐式拥有),但对于select new ... SellerDetailsDto,需要一个构造函数,其中包含您在select语句中提供的15个参数。 (认为​​错误消息需要一个只有id作为参数的构造函数 - 看起来好像错误来自不同的select new语句。)你没有这样的构造函数。

答案 1 :(得分:1)

问题是您在SellerDetailsDto中没有构造函数,它接受您在hql查询中传递的参数。将此构造函数添加到您的类:

public SellerDetailsDto(String productId, String sellerId,
            String sellerSku, Double sellPrice, Double transferPrice,
            Double sellerMRP, Double tradusCommission, Double baseShippingFee,
            Double addnShippingFee, String propogationLevel,
            String propogationValue, String warehouseName, int quantity,
            int maxShippingTime, int minShippingTime) {
        this.productId = productId;
        this.sellerId = sellerId;
        this.sellerSku = sellerSku;
        this.sellPrice = sellPrice;
        this.transferPrice = transferPrice;
        this.sellerMRP = sellerMRP;
        this.tradusCommission = tradusCommission;
        this.baseShippingFee = baseShippingFee;
        this.addnShippingFee = addnShippingFee;
        this.propogationLevel = propogationLevel;
        this.propogationValue = propogationValue;
        this.warehouseName = warehouseName;
        this.quantity = quantity;
        this.maxShippingTime = maxShippingTime;
        this.minShippingTime = minShippingTime;
    }

这可能会使其他一些代码停止工作,因为现在不会有这样的代码。是一个可用的默认构造函数。要解决此问题,请添加默认构造函数:

public SellerDetailsDto() {}