财产未找到例外

时间:2014-03-17 05:57:42

标签: java-ee netbeans-7 classnotfoundexception

我添加了category.java和CategoryFacade.java类来查询affablebean数据库的类别表。类别表包含两列,即&#34; id_cat&#34;和&#34;名称&#34;。如果我在我的index.jsp页面中使用<a href="category?${category.name}">它可以很好地用于代替&#34; name&#34;当我使用id_cat <a href="category?${category.id_cat}">时,它显示如下所示的错误。任何人都可以帮我解决这个问题。您可以在下面找到所有相关的页面代码供您查看。

HTTP Status 500 - Internal Server Error

type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'entity.Category' does not have the property 'id_cat'.

root cause

javax.el.PropertyNotFoundException: The class 'entity.Category' does not have the property 'id_cat'.

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.0 logs.
GlassFish Server Open Source Edition 4.0

HTTP Status 500 - Internal Server Error type Exception report messageInternal Server Error descriptionThe server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'entity.Category' does not have the property 'id_cat'. root cause javax.el.PropertyNotFoundException: The class 'entity.Category' does not have the property 'id_cat'. note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.0 logs. GlassFish Server Open Source Edition 4.0

这是我的Category.java代码

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, 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.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
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 sabin
 */
@Entity
@Table(name = "category")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Category.findAll", query = "SELECT c FROM Category c"),
    @NamedQuery(name = "Category.findByIdCat", query = "SELECT c FROM Category c WHERE c.idCat = :idCat"),
    @NamedQuery(name = "Category.findByName", query = "SELECT c FROM Category c WHERE c.name = :name")})
public class Category implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_cat")
    private Short idCat;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "name")
    private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "categoryId")
    private Collection<Product> productCollection;

    public Category() {
    }

    public Category(Short idCat) {
        this.idCat = idCat;
    }

    public Category(Short idCat, String name) {
        this.idCat = idCat;
        this.name = name;
    }

    public Short getIdCat() {
        return idCat;
    }

    public void setIdCat(Short idCat) {
        this.idCat = idCat;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public Collection<Product> getProductCollection() {
        return productCollection;
    }

    public void setProductCollection(Collection<Product> productCollection) {
        this.productCollection = productCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCat != null ? idCat.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 Category)) {
            return false;
        }
        Category other = (Category) object;
        if ((this.idCat == null && other.idCat != null) || (this.idCat != null && !this.idCat.equals(other.idCat))) {
            return false;
        }
        return true;
    }

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

}

这是我的CategoryFacade.java代码

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, 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.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
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 sabin
 */
@Entity
@Table(name = "category")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Category.findAll", query = "SELECT c FROM Category c"),
    @NamedQuery(name = "Category.findByIdCat", query = "SELECT c FROM Category c WHERE c.idCat = :idCat"),
    @NamedQuery(name = "Category.findByName", query = "SELECT c FROM Category c WHERE c.name = :name")})
public class Category implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_cat")
    private Short idCat;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "name")
    private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "categoryId")
    private Collection<Product> productCollection;

    public Category() {
    }

    public Category(Short idCat) {
        this.idCat = idCat;
    }

    public Category(Short idCat, String name) {
        this.idCat = idCat;
        this.name = name;
    }

    public Short getIdCat() {
        return idCat;
    }

    public void setIdCat(Short idCat) {
        this.idCat = idCat;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public Collection<Product> getProductCollection() {
        return productCollection;
    }

    public void setProductCollection(Collection<Product> productCollection) {
        this.productCollection = productCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCat != null ? idCat.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 Category)) {
            return false;
        }
        Category other = (Category) object;
        if ((this.idCat == null && other.idCat != null) || (this.idCat != null && !this.idCat.equals(other.idCat))) {
            return false;
        }
        return true;
    }

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

}

这是我的index.jsp页面。

1 个答案:

答案 0 :(得分:0)

在寻找解决方案并用我的代码进行大量实验后,我终于找到了解决方案。 正如你在我的index.jsp代码中看到的那样,我写了category.id_cat。

<a href="category?${category.id_cat}">

使用netbeans向导创建entiy类时应该非常小心。表“category”中的列名是id_cat,它在Category.java类中更改为idCat。虽然我认为它接受使用注释

在Category.java类中提到的相同名称id_cat
 @Column(name="id_cat")

但我没有看到变量声明在下面,即

private Short idCat

现在要获取我必须访问idCat而不是id_cat的值。我将代码<a href="category?${category.id_cat}">替换为<a href="category?${category}">,以查看在$ {categories}结果的类别变量中设置了哪些列和值。然后我发现它使用idCat = 1然后我回到我的代码并找到了初始化表中id_cat值的变量。它正如我上面提到的那样使用idCat变量。我用idCat替换了id_cat,现在它工作得很好。