title: How to use JPA with abstraction with WHERE clause?
body: <p>So I have a GeneralDao class and classes that implement this super class.</p>
  
  <p>Here is GeneralDao:</p>
  
  <pre><code>@Stateless
  public abstract class GeneralDao&lt;T&gt; {
  
      @PersistenceContext(unitName = "Persistence")
      EntityManager em;
  
      public List&lt;T&gt; getAll(){
          TypedQuery&lt;T&gt; typedQuery = em.createQuery("Select t from " + getClassType().getSimpleName() + " t", getClassType());
          return typedQuery.getResultList();
      }
  
  
      public T getWithId(int id){
          TypedQuery&lt;T&gt; typedQuery = em.createQuery("Select t from " + getClassType().getSimpleName() + " t WHERE t." + getSimpleNameWithLowerFirstLetter() +"Id=id", getClassType());
          return typedQuery.getSingleResult();
      }
  
      private String getSimpleNameWithLowerFirstLetter(){
          String string = getClassType().getSimpleName();
          string = Character.toLowerCase(
                  string.charAt(0)) + (string.length() &gt; 1 ? string.substring(1) : "");
          return string;
      }
  
      protected abstract Class&lt;T&gt; getClassType();
  
  }
  </code></pre>
  
  <p>And this is an example class that extends this class:</p>
  
  <pre><code>@Stateless
  public class ActorDao extends GeneralDao&lt;Actor&gt; implements Serializable {
  
      @Override
      protected Class&lt;Actor&gt; getClassType() {
          return Actor.class;
      }
  
      @Override
      public Actor getWithId(int id){
          TypedQuery&lt;Actor&gt; typedQuery =
                  em.createQuery("Select a From Actor a WHERE a.actorId =" + id,Actor.class);
          return typedQuery.getSingleResult();
      }    
  
  }
  </code></pre>
  
  <p>Now the problem is, I can use</p>
  
  <pre><code>actorDao.getAll()
  </code></pre>
  
  <p>without any problems. Note that this method is not overriden.</p>
  
  <p>However if I do not override</p>
  
  <pre><code> actorDao.getWithId(int id)
  </code></pre>
  
  <p>I am getting:</p>
  
  <pre><code>java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
  Exception Description: Error compiling the query [Select t from Actor t WHERE t.actorId=id], line 1, column 38: unknown identification variable [id]. The FROM clause of the query does not declare an identification variable [id].
  </code></pre>
  
  <p>Even the final queries are exactly the same, if it is not overriden as seen in here, it won't work.</p>
  
  <p>What is it that I am missing?</p>