title: MySQLSyntaxErrorException: Unknown column 'category' in 'field list'
body: <p>I have been coding around to create a shopping cart for my online store project. I have a table named "products" and an entity class from this table as followed;</p>
  
  <pre><code>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 &amp;&amp; other.productId != null) || (this.productId != null &amp;&amp; !this.productId.equals(other.productId))) {
              return false;
          }
          return true;
      }
  
      @Override
      public String toString() {
          return "entities.Products[ productId=" + productId + " ]";
      }
  }
  </code></pre>
  
  <p>To handle operations I have an ejb class named "operations" as followed;</p>
  
  <pre><code>package ejb;
  
  import entities.Products;
  import java.util.List;
  import javax.ejb.Stateless;
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  import javax.persistence.Query;
  
  /**
   *
   * @author fet
   */
  
  @Stateless
  public class operations {
  
      @PersistenceContext(unitName = "registerPU")
      private EntityManager em;
  
  
      public List&lt;Products&gt; retrieveProducts() {
  
          return  em.createQuery("SELECT p FROM Products p").getResultList();
      }
  }
  </code></pre>
  
  <p>and I have an xhtml file which I want to present my products;</p>
  
  <pre><code>&lt;h:dataTable value="#{index.products}" var="p"&gt;
  
          &lt;h:column&gt;
  
              &lt;f:facet name="header" /&gt;
              &lt;h:outputLink value="index.xhtml"/&gt;
              &lt;f:param   name="query" value="#{p.productId}"/&gt;
  
          &lt;/h:column&gt;
          .
          .
          .
          .
          .
      &lt;/h:dataTable&gt;
  </code></pre>
  
  <p>Finally I have RequestScoped bean named index;</p>
  
  <pre><code>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&lt;Products&gt; getProducts() {
          return operations.retrieveProducts();
      }
  }
  </code></pre>
  
  <p>But I am instantly getting this error:</p>
  
  <blockquote>
    <p>HTTP Status 500 - Internal Server Error<br>
    type Exception report<br>
    messageInternal Server Error<br>
    descriptionThe server encountered an internal error that prevented it from fulfilling this request.<br>
    exception<br>
    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</p>
  </blockquote>
  
  <pre><code>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
  </code></pre>
  
  <p>note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs.</p>
  
  <p>Any opinions or advice? Thanks in advance</p>