2012-05-22 32 views
0

我有一個Java應用程序,使用jpa顯示名爲MasterScrip的表中的數據。我想一個額外的字段添加到我的表,但是, 當我命名爲「改變」一個額外的字段添加到我的數據庫表MasterScrip我得到異常之後,當我刪除領域,應用程序工作正常內部異常:java.lang.NoSuchFieldException

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 + " ]"; 
    } 

} 

表結構:你是不是使用中有該領域的orm.xml文件

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 
+0

因此,您在表中添加了一列,但未將其添加到映射到此表的實體?向我們展示實體的代碼和表格的結構。 –

+0

@JB Nizet-編輯我的問題,包括表結構和映射到它的實體 – z22

回答

0

檢查。同時重啓你的服務器,並確保你沒有兩次映射這個類。