Ich habe programmiert, um einen Einkaufswagen für mein Online-Shop-Projekt zu erstellen. Ich habe eine Tabelle namens "Produkte" und eine Entitätsklasse aus dieser Tabelle wie folgt;MySQLSyntaxErrorException: Unbekannte Spalte 'Kategorie' in 'Feldliste'
package entities;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
*
* @author fet
*/
@Entity
@Table(name = "products")
@NamedQueries({
@NamedQuery(name = "Products.findAll", query = "SELECT p FROM Products p"),
@NamedQuery(name = "Products.findByProductId", query = "SELECT p FROM Products p WHERE p.productId = :productId"),
@NamedQuery(name = "Products.findByProductName", query = "SELECT p FROM Products p WHERE p.productName = :productName"),
@NamedQuery(name = "Products.findBySubCategoryName", query = "SELECT p FROM Products p WHERE p.subCategoryName = :subCategoryName"),
@NamedQuery(name = "Products.findByCategoryName", query = "SELECT p FROM Products p WHERE p.categoryName = :categoryName"),
@NamedQuery(name = "Products.findByCompanyName", query = "SELECT p FROM Products p WHERE p.companyName = :companyName"),
@NamedQuery(name = "Products.findByPrice", query = "SELECT p FROM Products p WHERE p.price = :price"),
@NamedQuery(name = "Products.findByTags", query = "SELECT p FROM Products p WHERE p.tags = :tags"),
@NamedQuery(name = "Products.findByProductQty", query = "SELECT p FROM Products p WHERE p.productQty = :productQty"),
@NamedQuery(name = "Products.findByLastUpdated", query = "SELECT p FROM Products p WHERE p.lastUpdated = :lastUpdated"),
@NamedQuery(name = "Products.findByHits", query = "SELECT p FROM Products p WHERE p.hits = :hits")})
public class Products implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "product_id")
private Integer productId;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 60)
@Column(name = "product-name")
private String productName;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 40)
@Column(name = "sub-category-name")
private String subCategoryName;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 40)
@Column(name = "category-name")
private String categoryName;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 40)
@Column(name = "company-name")
private String companyName;
@Basic(optional = false)
@NotNull
@Column(name = "price")
private double price;
@Lob
@Size(max = 65535)
@Column(name = "summary")
private String summary;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "tags")
private String tags;
@Basic(optional = false)
@NotNull
@Column(name = "product_qty")
private int productQty;
@Basic(optional = false)
@NotNull
@Column(name = "lastUpdated")
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdated;
@Basic(optional = false)
@NotNull
@Column(name = "hits")
private int hits;
public Products() {
}
public Products(Integer productId) {
this.productId = productId;
}
public Products(Integer productId, String productName, String subCategoryName, String categoryName, String companyName, double price, String tags, int productQty, Date lastUpdated, int hits) {
this.productId = productId;
this.productName = productName;
this.subCategoryName = subCategoryName;
this.categoryName = categoryName;
this.companyName = companyName;
this.price = price;
this.tags = tags;
this.productQty = productQty;
this.lastUpdated = lastUpdated;
this.hits = hits;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getSubCategoryName() {
return subCategoryName;
}
public void setSubCategoryName(String subCategoryName) {
this.subCategoryName = subCategoryName;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
public int getProductQty() {
return productQty;
}
public void setProductQty(int productQty) {
this.productQty = productQty;
}
public Date getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}
public int getHits() {
return hits;
}
public void setHits(int hits) {
this.hits = hits;
}
@Override
public int hashCode() {
int hash = 0;
hash += (productId != null ? productId.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 Products)) {
return false;
}
Products other = (Products) object;
if ((this.productId == null && other.productId != null) || (this.productId != null && !this.productId.equals(other.productId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "entities.Products[ productId=" + productId + " ]";
}
}
Um Operationen zu behandeln habe ich eine ejb-Klasse namens "operations" wie folgt;
und ich habe eine XHTML-Datei, die ich meine Produkte präsentieren möchte;
<h:dataTable value="#{index.products}" var="p">
<h:column>
<f:facet name="header" />
<h:outputLink value="index.xhtml"/>
<f:param name="query" value="#{p.productId}"/>
</h:column>
.
.
.
.
.
</h:dataTable>
Endlich habe ich RequestScoped bean benannter Index;
package WEB;
import ejb.operations;
import entities.Products;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
/**
*
* @author fet
*/
@Named(value = "index")
@RequestScoped
public class index implements Serializable {
@EJB
private operations operations;
public index() {
}
public List<Products> getProducts() {
return operations.rertrieveProducts();
}
}
Aber ich bekomme sofort Fehler, der sagt;
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
javax.servlet.ServletException
root cause
javax.ejb.EJBException
root cause
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'category' in 'field list'
Error Code: 1054
Call: SELECT product_id, category-name, company-name, hits, lastUpdated, price, product-name, product_qty, sub-category-name, summary, tags FROM products
Query: ReadAllQuery(referenceClass=Products sql="SELECT product_id, category-name, company-name, hits, lastUpdated, price, product-name, product_qty, sub-category-name, summary, tags FROM products")
root cause
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
note Der vollständige Stack-Traces der Ausnahme und ihre Ursachen sind in den Glassfish Server Open Source Edition 4.1.1 Protokolle zur Verfügung.
irgendwelche Meinungen oder Ratschläge? Vielen Dank im Voraus
Verwenden Sie Bindestriche in Spaltennamen nicht – mate64