title: Hibernate maps the time in Timestamp with time 00:00:00
body: <p>Consider the code : </p>
  
  <pre><code>import java.sql.Timestamp;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.util.Calendar;
  import java.util.Date;
  
  import javax.servlet.ServletException;
  
  import model.UserModel;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.Transaction;
  import org.hibernate.cfg.Configuration;
  import org.hibernate.service.ServiceRegistry;
  import org.hibernate.service.ServiceRegistryBuilder;
  
  
  /**
   * This class adds initial values to the DB 
   * @author X2
   *
   */
  public class InitialRecords {
  
      private static SessionFactory sessionFactory;
      private static ServiceRegistry serviceRegistry;
      private static final String HIBERNATE_USERS = "usersModel.hbm.xml";
  
      /**
       * 
       * @param myDabatase
       * @throws ServletException
       */
      public void insertInitialRecords(ChatDatabase myDabatase) throws ServletException
      {
          Session session = null;
          java.util.Date date= new java.util.Date();
          Timestamp stamp = new Timestamp(date.getTime());    // get time &amp; date
          Timestamp stamp2 = new Timestamp(date.getTime());   // get time &amp; date
          UserModel user = new UserModel("jackson" , stamp , "Some cool message");
          UserModel user2 = new UserModel("yohan" , stamp2 , "Another cool message");
  
          // Setting up HIBERNATE
          // now use Hibernate to put it in the DB
  
          try
          {
              Configuration cfg = new Configuration().addResource(HIBERNATE_USERS).configure();
              serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
              sessionFactory = cfg.buildSessionFactory(serviceRegistry);
  
              // now insert the record of the person using Hibernate
  
              session = sessionFactory.openSession();
              System.out.println("Inserting Person records");
              Transaction tx = session.beginTransaction();
  
              // save the persons before hibernating
  
              session.save(user);
              session.save(user2);
  
              // execute
              tx.commit();
              System.out.println("Done");
              session.close();
              sessionFactory.close();
  
          }
  
          catch (Exception exp)
          {
              System.out.println("Error , here is the description :");
              System.out.println(exp.toString());
              System.exit(0); // abort the program
          }
  
      }
  
  }
  </code></pre>
  
  <p>The UserModel class : </p>
  
  <pre><code>package model;
  
  import java.sql.Timestamp;
  
  public class UserModel 
  {
  
      static private int ctr;
      private int id;
      private String username;
      private Timestamp date;
      private String message;
  
      /**
       * Ctor
       * @param username
       * @param stamp
       * @param msg
       */
      public UserModel(String username , Timestamp stamp , String msg)
      {
          id = ctr + 1;
          ctr++;
          this.username = username;
          this.date = stamp;
          this.message = msg;
      }
  
      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 Timestamp getDate() {
          return date;
      }
  
      public void setDate(Timestamp date) {
          this.date = date;
      }
  
      public String getMessage() {
          return message;
      }
  
      public void setMessage(String message) {
          this.message = message;
      }
  
  
  
  }
  </code></pre>
  
  <p>When I map the records user and user2 , Hibernate maps the record with the time <code>00:00:00</code> </p>
  
  <p><img src="https://i.stack.imgur.com/QsQYc.gif" alt="enter image description here"></p>
  
  <p>How can I fix it ? </p>
  
  <p>Much appreciated </p>
  
  <p>Update : </p>
  
  <p>Here is how I create the table : </p>
  
  <pre><code>public void createHibernateTableMessagesUsers() throws SQLException, Exception
  {
  
      // this code assumes that the database "DATABASE_NAME" already exists
      // so the user must create that database before running the below code !!!
      try
      {
          Class.forName(FORNAME_URL);
          m_connectionHibernate = DriverManager.getConnection(URL , USERNAME , PASSWORD);
          m_statementHibernate = m_connectionHibernate.createStatement();
  
          m_statementHibernate.executeQuery("USE " + DATABASE_NAME);      // the name of the DATABASE
          m_statementHibernate.executeUpdate (
                  "CREATE TABLE IF NOT EXISTS "+ MESSAGES_TABLE +" ("
                  + "Username CHAR(40) ,  Message TEXT  , Date TIMESTAMP ,"
                          + " id INT AUTO_INCREMENT primary key NOT NULL" + ")");
      }
  </code></pre>