2012-06-06 44 views
0

我正在使用以下查詢 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)「 +」from PriceDetails p,AvailabilityDetails a「 +」其中a.productId = p.productId「 +」和a.sellerSku = p.sellerSku 「 +」和a.sellerId =:sellerId「;錯誤:org.hibernate.PropertyNotFoundException:類中沒有適當的構造函數:com.a.offering.dto.SellerDetailsDto

在執行我收到錯誤

org.hibernate.hql.ast.QuerySyntaxException:找不到階級[com.a.offering.dto.SellerDetailsDto]合適的構造函數[選擇NEW com.s.offering .dto.SellerDetailsDto(p.productId)from com.a.offering.db.domain.PriceDetails p,com.a.offering.db.domain.AvailabilityDetails a where a.productId = p.productId and a.sellerSku = p。 sellerSku and a.sellerId =:sellerId] at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54) at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47) 在org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82 ) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185) at 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) { 

一個}

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

} 
+0

您可以發佈com.tradus.offering.dto.SellerDetailsDto的代碼嗎? – Pablo

回答

2

Hibernate需要構造至少包私有(即默認值)的可見性。

通常無參數構造函數是必要的(您隱含地),但對於您的select new ... SellerDetailsDto需要一個構造函數,它帶有您在select語句中給出的15個參數。 (認爲​​錯誤消息要求只有id作爲參數的構造函數 - 看起來好像錯誤是來自不同的select new語句。)您沒有這樣的構造函數。

+0

嗨johanna,謝謝你的幫助! –

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() {} 
相關問題