title: Hibnernate insert or update datetime mysql always get 12:00:00 or 00:00:00
body: <p>Im new in hibernate</p>
  
  <p>I write a small application with hibernate and struts2</p>
  
  <p>my problem is </p>
  
  <p>when i update datetime my time will be 00:00:00 or 12:00:00 it not correct to what i choose like 04:50:10 or 18:20:11</p>
  
  <p>I try many times but it till not work</p>
  
  <p>In my form i have a field is string and then i convert it into date and then update it with hibernate</p>
  
  <p>my convert code </p>
  
  <pre><code>public Date convertStringToDate(String str) {
          Date date = null;
          SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss a");
          try {
              date = formatter.parse(str);
          } catch (ParseException ex) {
              Logger.getLogger(NewsAdminAction.class.getName()).log(Level.SEVERE, null, ex);
          }
          return date;
      }
  
      public String convertDateToString(Date date) {
          SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss a");
          String str = formatter.format(date);
          return str;
      }
  </code></pre>
  
  <p>my update code hibernate</p>
  
  <pre><code>//create session begin transaction
  
      String sqlNoThumb = "UPDATE News set title = :title, info = :info, publicdate = :publicdate, active = :active, titleviet = :titleviet where idnews = :idnews";
  
      Query query = session.createQuery(sqlNoThumb);
                      query.setString("title", news.getTitle());
                      query.setString("info", news.getInfo());
                      query.setDate("publicdate", news.getPublicdate());
                      query.setInteger("active", news.getActive());
                      query.setString("titleviet", news.getTitleviet());
                      query.setInteger("idnews", news.getIdnews());
                      result = query.executeUpdate();
  </code></pre>