内部异常:java.lang.NoSuchFieldException

时间:2012-05-22 15:24:09

标签: java-ee jpa

我有一个java应用程序,使用jpa显示名为MasterScrip的表中的数据。我希望在我的桌子上添加一个额外的字段,但是, 当我向我的数据库表MasterScrip添加一个名为'change'的额外字段时,我得到以下异常,当我删除该字段时,该应用程序正常工作

Exception [EclipseLink-0] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.IntegrityException
    Descriptor Exceptions: 
    ---------------------------------------------------------
    Exception [EclipseLink-59] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DescriptorException
    Exception Description: The instance variable [change] is not defined in the domain class [entity.MasterScrip], or it is not accessible.
    Internal Exception: java.lang.NoSuchFieldException: change
    Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[change-->StockCommodityDB.MasterScrip.Change]
    Descriptor: RelationalDescriptor(entity.MasterScrip --> [DatabaseTable(StockCommodityDB.MasterScrip)])

这个例外可能是什么原因?我该如何解决?

编辑: MasterScrip.java

@Entity
@Table(name = "MasterScrip", catalog = "StockCommodityDB", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MasterScrip.findAll", query = "SELECT m FROM MasterScrip m"),
    @NamedQuery(name = "MasterScrip.findByScripID", query = "SELECT m FROM MasterScrip m WHERE m.scripID = :scripID"),
    @NamedQuery(name = "MasterScrip.findByScripSymbol", query = "SELECT m FROM MasterScrip m WHERE m.scripSymbol = :scripSymbol"),
    @NamedQuery(name = "MasterScrip.findByType", query = "SELECT m FROM MasterScrip m WHERE m.type = :type"),
    @NamedQuery(name = "MasterScrip.findByCompanyName", query = "SELECT m FROM MasterScrip m WHERE m.companyName = :companyName"),
    @NamedQuery(name = "MasterScrip.findByLastTradedPrice", query = "SELECT m FROM MasterScrip m WHERE m.lastTradedPrice = :lastTradedPrice"),
    @NamedQuery(name = "MasterScrip.findByLastTradedQuantity", query = "SELECT m FROM MasterScrip m WHERE m.lastTradedQuantity = :lastTradedQuantity"),
    @NamedQuery(name = "MasterScrip.findByOpenPrice", query = "SELECT m FROM MasterScrip m WHERE m.openPrice = :openPrice"),
    @NamedQuery(name = "MasterScrip.findByHighPrice", query = "SELECT m FROM MasterScrip m WHERE m.highPrice = :highPrice"),
    @NamedQuery(name = "MasterScrip.findByLowPrice", query = "SELECT m FROM MasterScrip m WHERE m.lowPrice = :lowPrice"),
    @NamedQuery(name = "MasterScrip.findByTotalTradedQuantity", query = "SELECT m FROM MasterScrip m WHERE m.totalTradedQuantity = :totalTradedQuantity"),
    @NamedQuery(name = "MasterScrip.findByVolume", query = "SELECT m FROM MasterScrip m WHERE m.volume = :volume"),
    @NamedQuery(name = "MasterScrip.findByExchange", query = "SELECT m FROM MasterScrip m WHERE m.exchange = :exchange"),
    @NamedQuery(name = "MasterScrip.findByBrokerageCharge", query = "SELECT m FROM MasterScrip m WHERE m.brokerageCharge = :brokerageCharge"),
    @NamedQuery(name = "MasterScrip.findByPreviousClose", query = "SELECT m FROM MasterScrip m WHERE m.previousClose = :previousClose"),
    @NamedQuery(name = "MasterScrip.findByChange", query = "SELECT m FROM MasterScrip m WHERE m.change = :change")})
public class MasterScrip implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "ScripID", nullable = false)
    private Integer scripID;
    @Size(max = 15)
    @Column(name = "ScripSymbol", length = 15)
    private String scripSymbol;
    @Size(max = 10)
    @Column(name = "Type", length = 10)
    private String type;
    @Size(max = 50)
    @Column(name = "CompanyName", length = 50)
    private String companyName;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "LastTradedPrice", precision = 22)
    private Double lastTradedPrice;
    @Column(name = "LastTradedQuantity")
    private Integer lastTradedQuantity;
    @Column(name = "OpenPrice", precision = 22)
    private Double openPrice;
    @Column(name = "HighPrice", precision = 22)
    private Double highPrice;
    @Column(name = "LowPrice", precision = 22)
    private Double lowPrice;
    @Column(name = "TotalTradedQuantity")
    private Integer totalTradedQuantity;
    @Column(name = "Volume")
    private Integer volume;
    @Size(max = 30)
    @Column(name = "Exchange", length = 30)
    private String exchange;
    @Column(name = "BrokerageCharge", precision = 22)
    private Double brokerageCharge;
    @Column(name = "PreviousClose", precision = 22)
    private Double previousClose;
    @Column(name = "Change", precision = 22)
    private Double change;
    @JoinColumn(name = "CommoditySubCategoryID", referencedColumnName = "CommoditySubCategoryID")
    @ManyToOne(fetch = FetchType.EAGER)
    private CommoditySubCategoryMaster commoditySubCategoryID;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "scripID", fetch = FetchType.EAGER)
    private Collection<UserStock> userStockCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "scripID", fetch = FetchType.EAGER)
    private Collection<UserTrack> userTrackCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "scripID", fetch = FetchType.EAGER)
    private Collection<OrderStock> orderStockCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "scripID", fetch = FetchType.EAGER)
    private Collection<TradeStock> tradeStockCollection;

    public MasterScrip() {
    }

    public MasterScrip(Integer scripID) {
        this.scripID = scripID;
    }

    public Integer getScripID() {
        return scripID;
    }

    public void setScripID(Integer scripID) {
        this.scripID = scripID;
    }

    public String getScripSymbol() {
        return scripSymbol;
    }

    public void setScripSymbol(String scripSymbol) {
        this.scripSymbol = scripSymbol;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public Double getLastTradedPrice() {
        return lastTradedPrice;
    }

    public void setLastTradedPrice(Double lastTradedPrice) {
        this.lastTradedPrice = lastTradedPrice;
    }

    public Integer getLastTradedQuantity() {
        return lastTradedQuantity;
    }

    public void setLastTradedQuantity(Integer lastTradedQuantity) {
        this.lastTradedQuantity = lastTradedQuantity;
    }

    public Double getOpenPrice() {
        return openPrice;
    }

    public void setOpenPrice(Double openPrice) {
        this.openPrice = openPrice;
    }

    public Double getHighPrice() {
        return highPrice;
    }

    public void setHighPrice(Double highPrice) {
        this.highPrice = highPrice;
    }

    public Double getLowPrice() {
        return lowPrice;
    }

    public void setLowPrice(Double lowPrice) {
        this.lowPrice = lowPrice;
    }

    public Integer getTotalTradedQuantity() {
        return totalTradedQuantity;
    }

    public void setTotalTradedQuantity(Integer totalTradedQuantity) {
        this.totalTradedQuantity = totalTradedQuantity;
    }

    public Integer getVolume() {
        return volume;
    }

    public void setVolume(Integer volume) {
        this.volume = volume;
    }

    public String getExchange() {
        return exchange;
    }

    public void setExchange(String exchange) {
        this.exchange = exchange;
    }

    public Double getBrokerageCharge() {
        return brokerageCharge;
    }

    public void setBrokerageCharge(Double brokerageCharge) {
        this.brokerageCharge = brokerageCharge;
    }

    public Double getPreviousClose() {
        return previousClose;
    }

    public void setPreviousClose(Double previousClose) {
        this.previousClose = previousClose;
    }

    public Double getChange() {
        return change;
    }

    public void setChange(Double change) {
        this.change = change;
    }

    public CommoditySubCategoryMaster getCommoditySubCategoryID() {
        return commoditySubCategoryID;
    }

    public void setCommoditySubCategoryID(CommoditySubCategoryMaster commoditySubCategoryID) {
        this.commoditySubCategoryID = commoditySubCategoryID;
    }

    @XmlTransient
    public Collection<UserStock> getUserStockCollection() {
        return userStockCollection;
    }

    public void setUserStockCollection(Collection<UserStock> userStockCollection) {
        this.userStockCollection = userStockCollection;
    }

    @XmlTransient
    public Collection<UserTrack> getUserTrackCollection() {
        return userTrackCollection;
    }

    public void setUserTrackCollection(Collection<UserTrack> userTrackCollection) {
        this.userTrackCollection = userTrackCollection;
    }

    @XmlTransient
    public Collection<OrderStock> getOrderStockCollection() {
        return orderStockCollection;
    }

    public void setOrderStockCollection(Collection<OrderStock> orderStockCollection) {
        this.orderStockCollection = orderStockCollection;
    }

    @XmlTransient
    public Collection<TradeStock> getTradeStockCollection() {
        return tradeStockCollection;
    }

    public void setTradeStockCollection(Collection<TradeStock> tradeStockCollection) {
        this.tradeStockCollection = tradeStockCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (scripID != null ? scripID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MasterScrip)) {
            return false;
        }
        MasterScrip other = (MasterScrip) object;
        if ((this.scripID == null && other.scripID != null) || (this.scripID != null && !this.scripID.equals(other.scripID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.MasterScrip[ scripID=" + scripID + " ]";
    }

}

表格结构:

CREATE TABLE `MasterScrip` (
  `ScripID` int(11) NOT NULL AUTO_INCREMENT,
  `ScripSymbol` varchar(15) DEFAULT NULL,
  `Type` varchar(10) DEFAULT NULL,
  `CommoditySubCategoryID` int(11) DEFAULT NULL,
  `CompanyName` varchar(50) DEFAULT NULL,
  `LastTradedPrice` double DEFAULT NULL,
  `LastTradedQuantity` int(11) DEFAULT NULL,
  `OpenPrice` double DEFAULT NULL,
  `HighPrice` double DEFAULT NULL,
  `LowPrice` double DEFAULT NULL,
  `TotalTradedQuantity` int(11) DEFAULT NULL,
  `Volume` int(11) DEFAULT NULL,
  `Exchange` varchar(30) DEFAULT NULL,
  `BrokerageCharge` double DEFAULT NULL,
  `PreviousClose` double DEFAULT NULL,
  `Change` double DEFAULT NULL,
  PRIMARY KEY (`ScripID`),
  KEY `comSubCatID_fk_constraint` (`CommoditySubCategoryID`),
  CONSTRAINT `comSubCatID_fk_constraint` FOREIGN KEY (`CommoditySubCategoryID`) REFERENCES `CommoditySubCategoryMaster` (`CommoditySubCategoryID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1

1 个答案:

答案 0 :(得分:0)

检查您是否使用了包含该字段的orm.xml文件。还要重新启动服务器并确保没有两次映射该类。