title: Get Generic list using Hibernate criteria
body: <p>I have two classes State and City and two separate <strong>DAO</strong> objects to perform <strong>CRUD</strong> operation on <em>State</em> and <em>City</em>.</p>
  
  <pre><code>List&lt;Chapter&gt; getAllStates();
  int save(State state);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>List&lt;City&gt; getAllCities();
  int save(Citycity);
  </code></pre>
  
  <p>I can have many more classes which need to have their own DAOs.</p>
  
  <p>I want to use generic so that I will have only one <strong>DAO</strong> object which can perform <strong>CRUD</strong> on any given type.</p>
  
  <p>I am trying.</p>
  
  <pre><code>@Override
      public &lt;T&gt; List&lt;T&gt; getAllItems() {
          return sessionFactory.getCurrentSession().createCriteria&lt;T&gt;().list();
      }
  </code></pre>
  
  <p>gives the following error:</p>
  
  <blockquote>
    <p>Syntax error on token "(", Expression expected after this token"</p>
  </blockquote>
  
  <p>and </p>
  
  <pre><code>@Override
      public &lt;T&gt; List&lt;T&gt; getAllItems() {
          return sessionFactory.getCurrentSession().createCriteria(T).list();
      }
  </code></pre>
  
  <p>which shows </p>
  
  <blockquote>
    <p>T cannot be resolved to a variable</p>
  </blockquote>
  
  <p>Is there a way to achieve what I want?</p>
  
  <p>If yes please help me with example or correcting my code.</p>
  
  <p>Thanks</p>