title: How to select data from a mysql table using Hibernate
body: <p>I have my hibernate.cfg.xml file as,</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.bytecode.use_reflection_optimizer"&gt;false&lt;/property&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;123789&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://127.0.0.1:3306/ofm_mnu_jvs&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;user1&lt;/property&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;mapping resource="org/ofm/mnu/mappings/ActMonths.hbm.xml"&gt;&lt;/mapping&gt;
      &lt;/session-factory&gt;
  </code></pre>
  
  <p>Mapping,</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="org.ofm.mnu.mappings.ActMonths" table="act_months" catalog="ofm_mnu_jvs"&gt;
          &lt;composite-id name="id" class="org.ofm.mnu.mappings.ActMonthsId"&gt;
              &lt;key-property name="year" type="int"&gt;
                  &lt;column name="year" /&gt;
              &lt;/key-property&gt;
              &lt;key-property name="monthNo" type="int"&gt;
                  &lt;column name="month_no" /&gt;
              &lt;/key-property&gt;
          &lt;/composite-id&gt;        
  
          &lt;property name="lastDay" type="java.lang.Integer"&gt;
              &lt;column name="last_day" /&gt;
          &lt;/property&gt;
          &lt;property name="month" type="string"&gt;
              &lt;column name="month" length="20" /&gt;
          &lt;/property&gt;
          &lt;property name="user" type="string"&gt;
              &lt;column name="user" length="20" /&gt;
          &lt;/property&gt;
          &lt;property name="sysDateTime" type="timestamp"&gt;
              &lt;column name="sys_date_time" length="19" not-null="false" /&gt;
          &lt;/property&gt;
          &lt;property name="status" type="boolean"&gt;
              &lt;column name="status" not-null="true" /&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>When I am trying to select data from the database as,</p>
  
  <pre><code>Session session = HibernateUtil.getSessionFactory().openSession();
  String SQL_QUERY = "from act_months";
  
          Query query = session.createQuery(SQL_QUERY);
          session.getTransaction().commit();
          for (Iterator it = query.iterate(); it.hasNext();) {
              Object[] row = (Object[]) it.next();
              System.out.println("ID: " + row[0]);
  
          }
  </code></pre>
  
  <p>I get following error,</p>
  
  <pre><code>INFO: Not binding factory to JNDI, no JNDI name configured
  Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: act_months is not mapped [from act_months]
      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 org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
  </code></pre>
  
  <p>please tell me where I am wrong.</p>