title: Why I obtain this HibernateException related to a named query in this Spring project?
body: <p>I am absolutly new in Hibernate and Spring development and I have the following problem</p>
  
  <p>I have this entity class named KM_ProjectInfoStatus that map a DB table named KM_PROJECT_INFO_STATUS, so I have this class:</p>
  
  <pre><code>package egp.prc.km.model;
  
  import javax.persistence.*;
  import java.io.Serializable;
  
  @NamedQueries({
          @NamedQuery(name = "kmProjectInfoStatusList", query = "select status from KM_PROJECT_INFO_STATUS status order by status.idProjectInfoStatus") ,
          @NamedQuery(name = "kmProjectInfoStatusById", query = "SELECT status FROM KM_PROJECT_INFO_STATUS status where lower(status.idProjectInfoStatus) = :statusId")
  })
  
  @Entity
  @Table(name = "KM_PROJECT_INFO_STATUS")
  public class KM_ProjectInfoStatus implements Serializable {
  
      @Id
      @GeneratedValue
      private Long idProjectInfoStatus;
  
      @Column(name = "foldertech")
      private Long foldertech;
  
      @Column(name = "folderproject")
      private Long folderproject;
  
      public Long getIdProjectInfoStatus() {
          return idProjectInfoStatus;
      }
  
      public void setIdProjectInfoStatus(Long idProjectInfoStatus) {
          this.idProjectInfoStatus = idProjectInfoStatus;
      }
  
      public Long getFoldertech() {
          return foldertech;
      }
  
      public void setFoldertech(Long foldertech) {
          this.foldertech = foldertech;
      }
  
      public Long getFolderproject() {
          return folderproject;
      }
  
      public void setFolderproject(Long folderproject) {
          this.folderproject = folderproject;
      }
  }
  </code></pre>
  
  <p>As you can see in the previous snippet, uppon the class are definied 2 <strong>named queries</strong>, these:</p>
  
  <pre><code>@NamedQueries({
          @NamedQuery(name = "kmProjectInfoStatusList", query = "select status from KM_PROJECT_INFO_STATUS status order by status.idProjectInfoStatus") ,
          @NamedQuery(name = "kmProjectInfoStatusById", query = "SELECT status FROM KM_PROJECT_INFO_STATUS status where lower(status.idProjectInfoStatus) = :statusId")
  })
  </code></pre>
  
  <p>1) The first one is named <strong>kmProjectInfoStatusList</strong> and select a list of rows from my <strong>KM_PROJECT_INFO_STATUS</strong> table.</p>
  
  <p>2) The second one is named <strong>kmProjectInfoStatusById</strong> and select a single row from my <strong>KM_PROJECT_INFO_STATUS</strong> table using the id in the where condition.</p>
  
  <p>Then I have to implement a Spring service that realize a DAO.</p>
  
  <p>So I first create an interface named as <strong>KMProjectInfoStatusService</strong> in which I declare the method of my DAO:</p>
  
  <pre><code>public interface KMProjectInfoStatusService {
  
      @Transactional
      public List&lt;KM_ProjectInfoStatus&gt; getProjectInfoStatusList();
  
      @Transactional
      public KM_ProjectInfoStatus getProjectInfoStatus(Long idProjectInfoStatus);
  }
  </code></pre>
  
  <p>I am absolutly new in Hibernate and Spring development and I have the following problem</p>
  
  <p>I have this entity class named KM_ProjectInfoStatus that map a DB table named KM_PROJECT_INFO_STATUS, so I have this class:</p>
  
  <pre><code>package egp.prc.km.model;
  
  import javax.persistence.*;
  import java.io.Serializable;
  
  @NamedQueries({
          @NamedQuery(name = "kmProjectInfoStatusList", query = "select status from KM_PROJECT_INFO_STATUS status order by status.name") ,
          @NamedQuery(name = "kmProjectInfoStatusById", query = "SELECT status  FROM KM_PROJECT_INFO_STATUS status  where lower(status.idProjectInfoStatus) = :statusId")
  })
  
  @Entity
  @Table(name = "KM_PROJECT_INFO_STATUS")
  public class KM_ProjectInfoStatus implements Serializable {
  
      @Id
      @GeneratedValue
      private Long idProjectInfoStatus;
  
      @Column(name = "foldertech")
      private Long foldertech;
  
      @Column(name = "folderproject")
      private Long folderproject;
  
      public Long getIdProjectInfoStatus() {
          return idProjectInfoStatus;
      }
  
      public void setIdProjectInfoStatus(Long idProjectInfoStatus) {
          this.idProjectInfoStatus = idProjectInfoStatus;
      }
  
      public Long getFoldertech() {
          return foldertech;
      }
  
      public void setFoldertech(Long foldertech) {
          this.foldertech = foldertech;
      }
  
      public Long getFolderproject() {
          return folderproject;
      }
  
      public void setFolderproject(Long folderproject) {
          this.folderproject = folderproject;
      }
  }
  </code></pre>
  
  <p>As you can see in the previous snippet, the class contains also 2 named queries, these:</p>
  
  <pre><code>@NamedQueries({
          @NamedQuery(name = "kmProjectInfoStatusList", query = "select status from KM_PROJECT_INFO_STATUS status order by status.name") ,
          @NamedQuery(name = "kmProjectInfoStatusById", query = "SELECT status  FROM KM_PROJECT_INFO_STATUS status  where lower(status.idProjectInfoStatus) = :statusId")
  })
  </code></pre>
  
  <p>Then I have to implement a Spring service that realize a DAO.</p>
  
  <p>So I first create an interface named as KMProjectInfoStatusService in which I declare the method of my DAO:</p>
  
  <p>public interface KMProjectInfoStatusService {</p>
  
  <pre><code>@Transactional
  public List&lt;KM_ProjectInfoStatus&gt; getProjectInfoStatusList();
  
  @Transactional
  public KM_ProjectInfoStatus getProjectInfoStatus(Long idProjectInfoStatus);
  </code></pre>
  
  <p>}</p>
  
  <p>Finally I create the <strong>KMProjectInfoStatusServiceImp</strong> class that implement the previous interface and that represent my concrete DAO:</p>
  
  <pre><code>@Repository("kmProjectInfoStatusService")
  public class KMProjectInfoStatusServiceImpl extends AbstractService implements KMProjectInfoStatusService {
  
      public List&lt;KM_ProjectInfoStatus&gt; getProjectInfoStatusList() {
          //return new KM_ProjectInfoStatus[0];  //To change body of implemented methods use File | Settings | File Templates.
  
          return getHibernateTemplate().execute(
                  new HibernateCallback&lt;List&lt;KM_ProjectInfoStatus&gt;&gt;() {
                      public List&lt;KM_ProjectInfoStatus&gt; doInHibernate(Session session) throws HibernateException, SQLException {
                          return getStatusList(session);
                      }
                  }
          );
      }
  
  
      public KM_ProjectInfoStatus getProjectInfoStatus(Long idProjectInfoStatus) {
          //return null;  //To change body of implemented methods use File | Settings | File Templates.
  
          final Long id = idProjectInfoStatus;
          return getHibernateTemplate().execute(
                  new HibernateCallback&lt;KM_ProjectInfoStatus&gt;() {
                      public KM_ProjectInfoStatus doInHibernate(Session session) throws HibernateException, SQLException {
                          return getStatus(id, session);
                      }
                  }
          );
      }
  
      private List&lt;KM_ProjectInfoStatus&gt; getStatusList(Session session) {
          //create query:
          Query query = session.getNamedQuery("kmProjectInfoStatusList");
          List&lt;KM_ProjectInfoStatus&gt; statusList =  query.list();
  
          return statusList;
      }
  
      private KM_ProjectInfoStatus getStatus(Long idProjectInfoStatus, Session session) {
          //create query:
          Query query = session.getNamedQuery("kmProjectInfoStatusById");
          query.setParameter("statusId", idProjectInfoStatus);
  
          KM_ProjectInfoStatus status = (KM_ProjectInfoStatus) query.uniqueResult();
  
          return status;
      }
  }
  </code></pre>
  
  <p>As you can see in this class I implement the 2 methods <strong>getProjectInfoStatusList()</strong> and <strong>getProjectInfoStatus()</strong> declared in the interface. These 2 methods use respectivelly the <strong>getStatusList()</strong> to perform the first named query to obtain the list and <strong>getStatus()</strong> that perform the second query to obtain an object from its id.</p>
  
  <p>The problem is that when I try to execute my project an <strong>HibernateException</strong> is throwns and I obtain the following error message in the stacktrace:</p>
  
  <pre><code>2014-12-29 16:25:44,210 [[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'] ERROR impl.SessionFactoryImpl.&lt;init&gt;(363) - Error in named query: kmProjectInfoStatusById
  org.hibernate.hql.ast.QuerySyntaxException: KM_PROJECT_INFO_STATUS is not mapped [SELECT status  FROM KM_PROJECT_INFO_STATUS status  where lower(status.idProjectInfoStatus) = :statusId]
      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)
      ................................................................................
      ................................................................................
      ................................................................................
      ................................................................................
  &lt;29-dic-2014 16.25.44 CET&gt; &lt;Error&gt; &lt;Deployer&gt; &lt;BEA-149202&gt; &lt;Encountered an exception while attempting to commit the 1 task for the application 'KM_Web_war_exploded'.&gt; 
  &lt;29-dic-2014 16.25.44 CET&gt; &lt;Warning&gt; &lt;Deployer&gt; &lt;BEA-149004&gt; &lt;Failures were detected while initiating deploy task for application 'KM_Web_war_exploded'.&gt; 
  &lt;29-dic-2014 16.25.44 CET&gt; &lt;Warning&gt; &lt;Deployer&gt; &lt;BEA-149078&gt; &lt;Stack trace for message 149004
  weblogic.application.ModuleException: :org.hibernate.HibernateException:Errors in named queries: kmProjectInfoStatusById, kmProjectInfoStatusList
      at org.hibernate.impl.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:365)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
      at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
      at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
      at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
      Truncated. see log file for complete stacktrace
  </code></pre>
  
  <p>Why? What could be the problem? What am I missing? How can I solve this issue?</p>