title: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [from User]
body: <p>I'm getting <strong>java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [from User]</strong> error. I've gone through these question, but didn't helped me. </p>
  
  <p><a href="https://stackoverflow.com/questions/23018836/org-hibernate-hql-internal-ast-querysyntaxexception-table-is-not-mapped">org.hibernate.hql.internal.ast.QuerySyntaxException: table is not mapped
  </a></p>
  
  <p><a href="https://stackoverflow.com/questions/9954590/hibernate-error-querysyntaxexception-users-is-not-mapped-from-users">Hibernate error - QuerySyntaxException: users is not mapped [from users]
  </a></p>
  
  <blockquote>
    <p>Database table image:</p>
  </blockquote>
  
  <p><strong>Database Table user.jpg</strong></p>
  
  <p><a href="https://i.stack.imgur.com/MJ6cV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MJ6cV.png" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>UserBean.java</p>
  </blockquote>
  
  <p>package model;</p>
  
  <pre><code>import java.util.ArrayList;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  import controller.Login;
  import controller.userinfo;
  import gfgshfhjdgfhjdhhjfhjd.iModel;
  
  @Entity
  @Table(name= "User")
   public class UserBean  implements iModel
   {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name="Id")
      private int id; 
      @Column(name="Username")
      private String username ;
      @Column(name="Password")
      private String password ;
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public UserBean(){}
      public ArrayList&lt;?&gt; getData() {
          return userinfo.getUser();
      }
  
  
   }
  </code></pre>
  
  <blockquote>
    <p>Userinfo.java</p>
  </blockquote>
  
  <pre><code>package controller;
  
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.hibernate.Session;
  
  import model.UserBean;
  import test.HibernateSessionFactory;
  
  
  public class Userinfo  {
  
      public static void saveUser(UserBean user) {
             Session session = HibernateSessionFactory.getSessionFactory().openSession();
             session.beginTransaction();
  
             session.save(user);
  
             session.getTransaction().commit();
            }
  
      public static ArrayList&lt;?&gt; getUser() {
             Session session = HibernateSessionFactory.getSessionFactory().openSession();
             session.beginTransaction();
  
             List&lt;UserBean&gt; list = (List&lt;UserBean&gt;)session.createQuery("from User").list();
             ArrayList&lt;String&gt; list2= new ArrayList&lt;String&gt;();
  
  
             for(int i=0;i&lt;list.size();i++) {
                 int tmp = list.get(i).getId();
                 StringBuilder sBuilder = new StringBuilder();
                 sBuilder.append(tmp);
                 list2.add(sBuilder.toString());
                 list2.add(list.get(i).getUsername());
                 list2.add(list.get(i).getPassword());
             }
  
             if (list != null) {
              for (int i = 0; i &lt; list.size(); i++) {
               System.out.println("User ID : " + list.get(i).getId());
               System.out.println("User First Name : "+ list.get(i).getUsername());
               System.out.println("User Last Name : "+ list.get(i).getPassword());
  
             }
             }
             session.getTransaction().commit();
             return list2;
            }
  
  }
  </code></pre>
  
  <blockquote>
    <p>hibernate.cfg.xml</p>
  </blockquote>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;!-- SQL Dialect --&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
          &lt;!-- Database Connection Settings --&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/project&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
          &lt;!-- Specifying Session Context --&gt;
          &lt;property name="hibernate.current_session_context_class"&gt;org.hibernate.context.internal.ThreadLocalSessionContext&lt;/property&gt;
  &lt;!--        &lt;property name="hibernate.hbm2ddl.auto"&gt;create&lt;/property&gt; --&gt;
          &lt;!-- Mapping With Model Class Containing Annotations --&gt;
          &lt;mapping class="model.UserBean" /&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <blockquote>
    <p>Error Log:</p>
  </blockquote>
  
  <pre><code>May 06, 2018 4:16:04 PM org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateService
  INFO: HHH000397: Using ASTQueryTranslatorFactory
  java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [from User]
      at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:133)
      at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
      at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:164)
      at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:670)
      at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:103)
      at controller.Userinfo.getUser(Userinfo.java:28)
      at model.UserBean.getData(UserBean.java:55)
      at controller.Login.doGet(Login.java:38)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
      at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2430)
      at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2419)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [from User]
      at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79)
      at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:217)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:141)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:115)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:77)
      at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)
      at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:553)
      at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:662)
      ... 26 more
  Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped
      at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:169)
      at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91)
      at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:79)
      at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:326)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3706)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3595)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:720)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:576)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:313)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:261)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:266)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:189)
      ... 32 more
  </code></pre>
  
  <p>Help Please .. Thanks</p>