title: org.hibernate.AnnotationException: No identifier specified for entity: login.Users
body: <p>I am getting an error while reuest goes to servlet ,I try alot for resolved this but not get proper solution. </p>
  
  <p><strong>Registration.java (Servlet class file)</strong></p>
  
  <pre><code>package login;
  
  import java.io.IOException;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  import org.hibernate.SessionFactory;
  
  @WebServlet("/Registration")
  public class Registration extends HttpServlet {
     private static final long serialVersionUID = 1L;
  
  
  public Registration() {
      super();
   }
  
  
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
       String username =  request.getParameter("username");
       String password =  request.getParameter("password");
       String name =  request.getParameter("name");
  
       Users u = new Users();
       u.setUsername(username);
       u.setPassword(password);
       u.setName(name);
  
       String uname = u.getUsername();
       System.out.println(uname);
       SessionFactory sessionFactory = new                 Configuration().configure().buildSessionFactory();
       Session session = sessionFactory.openSession();
          session.beginTransaction();
          session.save(u);
          session.getTransaction().commit();
          session.close();
          sessionFactory.close();
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Users.java</strong> this class is used to stored the user information in  "Users" table</p>
  
  <pre><code>package login;
  import javax.persistence.Entity;
  import javax.persistence.Table;
  @Entity
  @Table(name="Users")
  public class Users {
  private String username;
  private String password;
  private String name;
  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 String getName() {
      return name;
  }
  public void setName(String name) {
      this.name = name;
  }   
  }
  </code></pre>
  
  <p><strong>hibernate.cfg.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
   &lt;session-factory&gt;
      &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/login&lt;/property&gt;
      &lt;property name="connection.username"&gt;root&lt;/property&gt;
      &lt;property name="connection.password"&gt;&lt;/property&gt;
  
      &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
      &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
      &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
      &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;
  
  
        &lt;mapping class ="login.Users" /&gt; 
  
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>
  
  <p><a href="http://i.stack.imgur.com/mjhJZ.png" rel="nofollow">Folder structure</a></p>
  
  <p><strong>Console Logs</strong></p>
  
  <pre><code>EVERE: Servlet.service() for servlet [Registration] in context with path [/loginapp] threw exception
  org.hibernate.AnnotationException: No identifier specified for entity: login.Users
  at    org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:265)
  at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:211)
  at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:710)
  at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:245)
  at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:222)
  at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265)
  at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
  at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
  at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
  at login.Registration.doPost(Registration.java:47)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  at java.lang.Thread.run(Unknown Source)
  </code></pre>