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

Posted

技术标签:

【中文标题】错误:org.hibernate.PropertyNotFoundException:类中没有合适的构造函数:com.a.offering.dto.SellerDetailsDto【英文标题】:error: org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.a.offering.dto.SellerDetailsDto 【发布时间】:2012-06-06 06:49:39 【问题描述】:

我正在使用以下查询 字符串 queryString = "选择新的 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 " + "and a.sellerId = :sellerId";

执行时出错

org.hibernate.hql.ast.QuerySyntaxException:无法在类 [com.a.offering.dto.SellerDetailsDto] 上找到适当的构造函数 [从 com 中选择新的 com.s.offering.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 和 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) 

一个

    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;
    


【问题讨论】:

能把com.tradus.offering.dto.SellerDetailsDto的代码贴出来吗? 【参考方案1】:

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

通常需要一个无参数构造函数(你隐含地拥有它),但是对于你的select new ... SellerDetailsDto 需要一个带有你在 select 语句中提供的 15 个参数的构造函数。 (认为​​错误消息需要一个仅将 id 作为参数的构造函数 - 看起来错误是否来自不同的 select new 语句。)您没有这样的构造函数。

【讨论】:

【参考方案2】:

问题是您在 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() 

【讨论】:

【参考方案3】:

实际上这是您的根 pom 文件的问题。你想在你的 IDE 中安装 lombok 并在根 pom 文件中添加 lombok 的依赖项我希望它会工作

【讨论】:

嗨 D,如果您指的是 Lombok 构造函数注释之一,那么您应该在答案中明确说明,这是为不熟悉项目 lombok 及其如何提供帮助的人准备的

以上是关于错误:org.hibernate.PropertyNotFoundException:类中没有合适的构造函数:com.a.offering.dto.SellerDetailsDto的主要内容,如果未能解决你的问题,请参考以下文章

Pig 安装错误:错误 pig.Main:错误 2998:未处理的内部错误

Informix 错误:发生了语法错误。错误代码:-201

我收到一个错误:“MetaMask - RPC 错误:错误:错误:[ethjs-rpc] rpc 错误与有效负载”

错误精灵错误跟踪器错误

网页打开显示错误500是啥意思

PHP错误处理