7 Replies Latest reply: May 22, 2012 1:42 PM by 938991 RSS

    Internal Exception: java.lang.NoSuchFieldException

    938991
      i have a java app that displays data from a table called MasterScrip using jpa. i wish to add an extra field to my table but, when i add an extra field named 'change' to my database table MasterScrip i get following exception, when i remove the field, the app works fine

      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)])

      //stack trace with ejbTransactionRolledBackException

      entity MasterScrip.java:
      /*
      * To change this template, choose Tools | Templates
      * and open the template in the editor.
      */
      package entity;

      import java.io.Serializable;
      import java.util.Collection;
      import javax.persistence.Basic;
      import javax.persistence.CascadeType;
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.ManyToOne;
      import javax.persistence.NamedQueries;
      import javax.persistence.NamedQuery;
      import javax.persistence.OneToMany;
      import javax.persistence.Table;
      import javax.validation.constraints.NotNull;
      import javax.validation.constraints.Size;
      import javax.xml.bind.annotation.XmlRootElement;
      import javax.xml.bind.annotation.XmlTransient;

      /**
      *
      * @author root
      */
      @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 + " ]";
      }

      }

      what could be the reason of this exception? how do i solve it?
        • 1. Re: Internal Exception: java.lang.NoSuchFieldException
          gimbal2
          The reason for the exception is exactly what it describes: there is no field "change" in the entity. Since entities follow standard bean rules, that means there should be a public getter and a public setter method.

          HOWEVER, the code you post has that. So to me there can be only one possibility that would still cause the exception: wherever you are trying to run the application, the updated MasterScrip.class file is not deployed - you are still using the old one without the change property added to it.
          • 2. Re: Internal Exception: java.lang.NoSuchFieldException
            938991
            thanks for the quick reply. but can you please tell how to deploy that particular class file? i have already redeployed my app before running it.
            • 3. Re: Internal Exception: java.lang.NoSuchFieldException
              938991
              i cleaned and built the app and redeployed it. now i am getting the following exception:

              Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
              Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Change, CompanyName, Exchange, HighPrice, LastTradedPrice, LastTradedQuantity, L' at line 1
              Error Code: 1064
              Call: SELECT ScripID, BrokerageCharge, Change, CompanyName, Exchange, HighPrice, LastTradedPrice, LastTradedQuantity, LowPrice, OpenPrice, PreviousClose, ScripSymbol, TotalTradedQuantity, Type, Volume, CommoditySubCategoryID FROM StockCommodityDB.MasterScrip
              Query: ReadAllQuery(name="MasterScrip.findAll" referenceClass=MasterScrip sql="SELECT ScripID, BrokerageCharge, Change, CompanyName, Exchange, HighPrice, LastTradedPrice, LastTradedQuantity, LowPrice, OpenPrice, PreviousClose, ScripSymbol, TotalTradedQuantity, Type, Volume, CommoditySubCategoryID FROM StockCommodityDB.MasterScrip")
                   at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)

              where am i wrong?
              • 4. Re: Internal Exception: java.lang.NoSuchFieldException
                gimbal2
                I don't know; I'm not familiar with EclipseLink either so I wouldn't know what steps to take to investigate what is going on. If you were using Hibernate I would have something to offer.

                As a sanity check: try renaming the "change" field to something else. Just to rule out this is some kind of reserved keyword clash.
                • 5. Re: Internal Exception: java.lang.NoSuchFieldException
                  938991
                  thanks! change is a reserved keyword. i changed it to chnge and it worked. but again when i try to add another field say for eg. 'holdingValue' , it gives the previous exception

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

                  what could be the reason? i am stuck in this...
                  • 6. Re: Internal Exception: java.lang.NoSuchFieldException
                    gimbal2
                    what could be the reason?
                    You're doing something wrong. I can't make it any more specific than that, I can't look over your shoulder to see what you're doing. I advise you to do a bit of reading around about the tools you're using to see if there isn't a more programmer friendly way of building and deploying your stuff, as it is now it is obviously not working for you.
                    • 7. Re: Internal Exception: java.lang.NoSuchFieldException
                      938991
                      sorry for bothering you but pls refer the following steps and tell me if i am going wrong:

                      - i added a field 'holdingValue' in my table MasterScrip
                      -next i created the entity mappings by the option 'create entity classes from database'(mappings created automatically with fetch type= eager)
                      -next i recreated the web service from the ejb
                      -deployed the ejb
                      -debugged the app and got the error stated in my question

                      that's it!