title: SQL Query error in JSF, JPA application
body: <p>I have a problem with a query in my application. This is the query method doing the query:</p>
  
  <pre><code>public List&lt;Product&gt; obtainProductListByCategory(String category)
     {
        Query query = em.createQuery("SELECT p FROM PRODUCT p WHERE CATEGORY='" + category + "'");
        List&lt;Product&gt; ret = query.getResultList();
  
        if (ret == null)
        {
           return new ArrayList&lt;Product&gt;();
        }
        else
        {
           return ret;
        }
     } 
  </code></pre>
  
  <p>And this is the error: <code>javax.ejb.EJBException</code></p>
  
  <p>And in the trace I found:</p>
  
  <blockquote>
    <p>Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Syntax error parsing [SELECT * FROM PRODUCT WHERE CATEGORY='Humano']. [22, 22] A select statement must have a FROM clause. [7, 7] The left expression is missing from the arithmetic expression. [9, 22] The right expression is not an arithmetic expression</p>
  </blockquote>
  
  <p>Any ideas? My objective is to refresh a JSF datatable in my webpage.</p>
  
  <hr>
  
  <p>Edited my code based on @Ilya's answer, and now I got this exception</p>
  
  <blockquote>
    <p>Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
    Exception Description: Problem compiling [SELECT p FROM PRODUCT p WHERE CATEGORY='Humano']. 
    [14, 21] The abstract schema type 'PRODUCT' is unknown.
    [30, 38] The identification variable 'CATEGORY' is not defined in the FROM clause.</p>
  </blockquote>
  
  <hr>
  
  <p>As requested by @Ilya, I post my <code>Product</code> class:
  EDIT: Added @Table to the annotations.</p>
  
  <pre><code>package model;
  
  import java.io.Serializable;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  
  @Table
  @Entity
  public class Product implements Serializable, IProduct
  {
     private static final long serialVersionUID = 1L;
     @GeneratedValue(strategy = GenerationType.AUTO)
     @Id
     private String name;
     private int stock;
     private float price;
     private String category;
     private String description;
  
    @Override 
    public String getDescription() {
          return description;
      }
  
  
    public void setDescription(String description) {
          this.description = description;
      }
  
  
     public Product()
     {
     }
  
  
     public Product(String name, int stock, float price, String category, String description)
     {
        this.name = name;
        this.stock = stock;
        this.price = price;
        this.category = category;
        this.description = description;
     }
  
  
  
  
  
     @Override
     public String getName()
     {
        return name;
     }
  
  
     public void setName(String name)
     {
        this.name = name;
     }
  
  
     @Override
     public float getPrice()
     {
        return price;
     }
  
  
     public void setPrice(float price)
     {
        this.price = price;
     }
  
  
     @Override
     public int getStock()
     {
        return stock;
     }
  
  
     public void setStock(int stock)
     {
        this.stock = stock;
     }
  
  
     @Override
     public int hashCode()
     {
        return name.hashCode();
     }
  
  
     @Override
     public boolean equals(Object object)
     {
        if (!(object instanceof Product))
        {
           return false;
        }
        Product other = (Product) object;
        if (name.equals(other.getName()))
        {
           return true;
        }
        return false;
     }
  
     @Override
     public String getCategory()
     {
        return category;
     }
  
     @Override
     public String toString()
     {
        return "Marketv2.model.Product[ name=" + name + " ]";
     }
  
  }
  </code></pre>
  
  <p>Thanks for the help so far. Here I post another query in my application, which is working properly:</p>
  
  <pre><code>   public void removeProduct(Product g)
     {
        Query q = em.createQuery("SELECT x FROM BasketItem x WHERE x.product.name = '" + g.getName() + "'");
        List&lt;BasketItem&gt; bItems = q.getResultList();
        for (BasketItem i : bItems)
        {
           em.remove(i);
        }
  
        q = em.createQuery("DELETE FROM Product x WHERE x.name = '" + g.getName() + "'");
        q.executeUpdate();
     }
  }
  </code></pre>