无法转换为java.lang.String异常

时间:2012-11-02 11:35:17

标签: java

@Entity
@Table(name = "RateTransmissionDetails")
public class RateTransmissionDetails implements java.io.Serializable {

    private String spaceNum;
    private Integer rateInCent;


    public RateTransmissionDetails() {
    }
    public RateTransmissionDetails(String spaceNum,Integer rateInCent) {

        this.spaceNum=spaceNum;
        this.rateInCent=rateInCent;
    } 


    @Column(name = "SpaceNum", nullable = false)
    public String getSpaceNum() {
        return this.spaceNum;
    }

    public void setSpaceNum(String spaceNum) {
        this.spaceNum = spaceNum;
    }

    @Column(name = "RateInCent", nullable = false)
    public Integer getRateInCent() {
        return this.rateInCent;
    }

    public void setRateInCent(Integer rateInCent) {
        this.rateInCent = rateInCent;
    }

我的服务类是

Set<RateTransmissionDetails> rateTrmDtls = new HashSet<RateTransmissionDetails>();
rateTrmDtls.add((new RateTransmissionDetails("A",new Integer(20)));

我收到错误

  

2012-11-02 16:44:02,796 [http-6060-3] WARN duncansolutions.databus.external.controller.rate.RateController - 调用者的错误消息:com.duncansolutions.databus.external.bean.hibernate。 rate.RateTransmissionDetails无法强制转换为java.lang.String

任何人都可以告诉我如何去做。

1 个答案:

答案 0 :(得分:0)

Set<RateTransmissionDetails> rateTrmDtls = new HashSet<RateTransmissionDetails>(); 
rateTrmDtls.add(new RateTransmissionDetails("A",new Integer(20)));

这里没有错。当您使用该集rateTrmDtls执行某些操作时,可能会发生该错误,并且代码需要一组String

您能否在RateController

中显示使用该集的代码?