title: Hibernate 4 Criteria query returns empty list
body: <p>I am using Spring 4 and Hibernate 4 but the query always returns empty list even through there should be few rows.</p>
  
  <p>This is the model</p>
  
  <pre><code>@DynamicUpdate 
  @Table(appliesTo = "comments")
  public class Comment {
  
      @Id @GeneratedValue
      @Column(name = "id")
      private int id;
  
      @Column(name = "content")
      private String content;
  
  ... and some getters and setters ...
  </code></pre>
  
  <p>This is the Spring configuration part</p>
  
  <pre><code>&lt;beans:bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
      destroy-method="close"&gt;
      &lt;beans:property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
      &lt;beans:property name="url"
          value="jdbc:mysql://mydbroot/circle" /&gt;
      &lt;beans:property name="username" value="user" /&gt;
      &lt;beans:property name="password" value="password" /&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="sessionFactory"
      class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;beans:property name="dataSource" ref="dataSource" /&gt;
      &lt;beans:property name="configLocation" value="classpath:hibernate.cfg.xml" /&gt;
  &lt;/beans:bean&gt;
  
  &lt;tx:annotation-driven /&gt;
  &lt;beans:bean id="transactionManager"
      class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
      &lt;beans:property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="commentDao"
      class="com.hersbitcloud.cancercloud.models.circle.CommentDAO"&gt;
      &lt;beans:constructor-arg&gt;
          &lt;beans:ref bean="sessionFactory" /&gt;
      &lt;/beans:constructor-arg&gt;
  &lt;/beans:bean&gt;
  </code></pre>
  
  <p>The hibernate.cfg.xml file</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
  &lt;session-factory&gt;
      &lt;property name="dialect"&gt;
          org.hibernate.dialect.MySQLDialect
      &lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>
  
  <p>For the DAO</p>
  
  <pre><code>public class CommentDAO {
  
  private SessionFactory sessionFactory;
  
  public CommentDAO(SessionFactory sessionFactory){
      this.sessionFactory = sessionFactory;
  }
  
  @Transactional
  public List&lt;Comment&gt; GetComments() {
  
      @SuppressWarnings("unchecked")
      List&lt;Comment&gt; listComment = (List&lt;Comment&gt;) sessionFactory.getCurrentSession()
              .createCriteria(Comment.class).list();
  
      return listComment;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>In my controller</p>
  
  <pre><code>    @Autowired
  private CommentDAO commentDao;
  
  @RequestMapping(value = "/comment", method = RequestMethod.GET) //, produces="application/json")
  public int comment() {
  
      List&lt;Comment&gt; listComments = commentDao.GetComments();
      return listComments.size();
  
  }
  </code></pre>
  
  <p>It always shows <code>listComments.size()</code> is 0.</p>
  
  <p>What's the problem?</p>
  
  <p>I attach screenshot of the database to show that table name is correct.
  <a href="https://i.stack.imgur.com/GKymV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GKymV.jpg" alt="enter image description here"></a></p>