2013-02-17 81 views
1

每當我嘗試在netbeans中使用hibernate連接ireport時,我收到錯誤「未找到組件類:Sustainability.ProductionSavingId」。當我運行它時,程序沒有顯示任何錯誤,但是當我嘗試使用休眠將ireport連接到數據庫時,它會引發錯誤。我已經添加了所需的類路徑和jar文件。未找到組件類休眠

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<!-- Generated Feb 1, 2013 7:21:28 PM by Hibernate Tools 3.2.1.GA --> 
<hibernate-mapping> 
    <class name="Sustainability.Productionsaving" table="productionsaving"       catalog="gdp"> 
     <composite-id name="id" class="Sustainability.ProductionsavingId"> 
      <key-property name="categoryName" type="string"> 
       <column name="CategoryName" length="25" /> 
      </key-property> 
      <key-property name="date" type="timestamp"> 
       <column name="Date" length="19" /> 
      </key-property> 
     </composite-id> 
     <many-to-one name="users" class="Sustainability.Users" fetch="select"> 
      <column name="Username" length="20" /> 
     </many-to-one> 
     <many-to-one name="category" class="Sustainability.Category" update="false" insert="false" fetch="select"> 
      <column name="CategoryName" length="25" not-null="true" /> 
     </many-to-one> 
     <property name="savingAmount" type="java.lang.Double"> 
      <column name="SavingAmount" precision="22" scale="0" /> 
     </property> 
     <property name="quantity" type="java.lang.Double"> 
      <column name="Quantity" precision="22" scale="0" /> 
     </property> 
     <property name="unit" type="string"> 
      <column name="Unit" length="5" /> 
     </property> 
    </class> 
</hibernate-mapping> 



<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<!-- Generated Feb 1, 2013 7:21:28 PM by Hibernate Tools 3.2.1.GA --> 
<hibernate-mapping> 
    <class name="Sustainability.Productionsaving" table="productionsaving"       catalog="gdp"> 
     <composite-id name="id" class="Sustainability.ProductionsavingId"> 
      <key-property name="categoryName" type="string"> 
       <column name="CategoryName" length="25" /> 
      </key-property> 
      <key-property name="date" type="timestamp"> 
       <column name="Date" length="19" /> 
      </key-property> 
     </composite-id> 
     <many-to-one name="users" class="Sustainability.Users" fetch="select"> 
      <column name="Username" length="20" /> 
     </many-to-one> 
     <many-to-one name="category" class="Sustainability.Category" update="false" insert="false" fetch="select"> 
      <column name="CategoryName" length="25" not-null="true" /> 
     </many-to-one> 
     <property name="savingAmount" type="java.lang.Double"> 
      <column name="SavingAmount" precision="22" scale="0" /> 
     </property> 
     <property name="quantity" type="java.lang.Double"> 
      <column name="Quantity" precision="22" scale="0" /> 
     </property> 
     <property name="unit" type="string"> 
      <column name="Unit" length="5" /> 
     </property> 
    </class> 
</hibernate-mapping> 






/** 
* Productionsaving generated by hbm2java 
*/ 
public class Productionsaving implements java.io.Serializable { 


    private ProductionsavingId id; 
    private Users users; 
    private Category category; 
    private Double savingAmount; 
    private Double quantity; 
    private String unit; 

    public Productionsaving() { 
    } 


    public Productionsaving(ProductionsavingId id, Category category) { 
     this.id = id; 
     this.category = category; 
    } 
    public Productionsaving(ProductionsavingId id, Users users, Category category, Double savingAmount, Double quantity, String unit) { 
     this.id = id; 
     this.users = users; 
     this.category = category; 
     this.savingAmount = savingAmount; 
     this.quantity = quantity; 
     this.unit = unit; 
    } 

    public ProductionsavingId getId() { 
     return this.id; 
    } 

    public void setId(ProductionsavingId id) { 
     this.id = id; 
    } 
    public Users getUsers() { 
     return this.users; 
    } 

    public void setUsers(Users users) { 
     this.users = users; 
    } 
    public Category getCategory() { 
     return this.category; 
    } 

    public void setCategory(Category category) { 
     this.category = category; 
    } 
    public Double getSavingAmount() { 
     return this.savingAmount; 
    } 

    public void setSavingAmount(Double savingAmount) { 
     this.savingAmount = savingAmount; 
    } 
    public Double getQuantity() { 
     return this.quantity; 
    } 

    public void setQuantity(Double quantity) { 
     this.quantity = quantity; 
    } 
    public String getUnit() { 
     return this.unit; 
    } 

    public void setUnit(String unit) { 
     this.unit = unit; 
    } 
} 


    import java.util.Date; 

/** 
* ProductionsavingId generated by hbm2java 
*/ 
public class ProductionsavingId implements java.io.Serializable { 


    private String categoryName; 
    private Date date; 

    public ProductionsavingId() { 
    } 

    public ProductionsavingId(String categoryName, Date date) { 
     this.categoryName = categoryName; 
     this.date = date; 
    } 

    public String getCategoryName() { 
     return this.categoryName; 
    } 

    public void setCategoryName(String categoryName) { 
     this.categoryName = categoryName; 
    } 
    public Date getDate() { 
     return this.date; 
    } 

    public void setDate(Date date) { 
     this.date = date; 
    } 


    public boolean equals(Object other) { 
     if ((this == other)) return true; 
     if ((other == null)) return false; 
     if (!(other instanceof ProductionsavingId)) return false; 
     ProductionsavingId castOther = (ProductionsavingId) other; 

     return ((this.getCategoryName()==castOther.getCategoryName()) || (this.getCategoryName()!=null && castOther.getCategoryName()!=null && this.getCategoryName().equals(castOther.getCategoryName()))) 
&& ((this.getDate()==castOther.getDate()) || (this.getDate()!=null && castOther.getDate()!=null && this.getDate().equals(castOther.getDate()))); 
    } 

    public int hashCode() { 
     int result = 17; 

     result = 37 * result + (getCategoryName() == null ? 0 : this.getCategoryName().hashCode()); 
     result = 37 * result + (getDate() == null ? 0 : this.getDate().hashCode()); 
     return result; 
    } 


} 

回答

0

該錯誤表示您引用的類不存在於類路徑中。確保你引用了正確的包名和類名。你的包名對我來說似乎不是標準。它應該像

com.mycompany.whatever.Sustainability

所以一定要確保你不會錯過那一個。另外我注意到在你粘貼的錯誤中,ProductionSavingId的外殼在你所顯示的hbm中不一樣。也許它的區分大小寫不匹配。