title: Hibernate throws strange error: Class is not mapped
body: <p>this is the error</p>
  
  <pre><code>org.hibernate.hql.ast.QuerySyntaxException: Payment is not mapped [select p from Payment p]
  </code></pre>
  
  <p>I don't understand how come this error is thrown, the class should be mapped as I will show you briefly. I have a very basic config, like this one: <a href="http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/ch01.html" rel="noreferrer">http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/ch01.html</a> </p>
  
  <p>I have tried to add the mapping definition into hibernate.cfg.xml and I have also tried to add it programmatically. Neither of them worked. Could anybody tell me what am I missing here? (it is not the first time I put together a Hibernate project)</p>
  
  <p>this is the hibernate.cfg.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
    &lt;session-factory&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/paymentsdatabase&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;xxx&lt;/property&gt;
      &lt;property name="hibernate.connection.password"&gt;xxx&lt;/property&gt;
      &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt;
      &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;
  
      &lt;property name="hibernate.hbm2ddl.auto"&gt;create&lt;/property&gt;
  
      &lt;!--  &lt;mapping class="com.lsyh.swati.zk.model.Payment"/&gt; --&gt;
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>the database connection is working fine, I have tested that</p>
  
  <p>this is the static initializer in my HibernateUtil</p>
  
  <pre><code>static {
      try {
  
          // Create the SessionFactory from standard (hibernate.cfg.xml) 
          // config file.
          sessionFactory = new AnnotationConfiguration()
              .addPackage("com.lsyh.swati.zk.model")
              .addAnnotatedClass(Payment.class)
              .configure().buildSessionFactory();
      } catch (Throwable ex) {
          // Log the exception. 
          System.err.println("Initial SessionFactory creation failed. " + ex);
          throw new ExceptionInInitializerError(ex);
      }
  }
  </code></pre>
  
  <p>and this is where I use the sessionFactory in the PaymentIODb class:</p>
  
  <pre><code>public static List&lt;Payment&gt; readDataFromDb(){
          StatelessSession session = StoreHibernateUtil.getSessionFactory().openStatelessSession();
          Query query = session.createQuery("select p from Payment p");
          List&lt;Payment&gt; payments = query.list();
          session.close();
          return payments;
  }    
  </code></pre>
  
  <p>this is the stack trace</p>
  
  <pre><code>org.hibernate.hql.ast.QuerySyntaxException: Payment is not mapped [select p from Payment p]
      at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
      at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
      at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
      at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
      at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
      at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
      at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
      at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
      at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
      at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
      at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
      at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
      at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
      at org.hibernate.engine.query.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:77)
      at org.hibernate.engine.query.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:56)
      at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
      at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
      at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
      at com.lsyh.swati.zk.controller.PaymentIODb.readDataFromDb(PaymentIODb.java:35)
      at com.lsyh.swati.zk.controller.PaymentIODb.resolveVariable(PaymentIODb.java:20
  </code></pre>