title: Incorrect datetime value Hibernate
body: <p>I am new to hibernate and still learning, I'm getting the stack trace below for the following code: </p>
  
  <pre><code>package com.simpleprogrammer;
  
  import org.hibernate.Session;
  import java.util.Date;
  
  public class Program {
  public static void main(String[] args) {
      System.out.println(org.hibernate.Version.getVersionString());
      System.out.println("Creating session!");
      Session session = HibernateUtilities.getSessionFactory().openSession();
      session.beginTransaction();
  
      User user = new User();
      user.setName("Joe");
      user.addHistory(new UserHistory(new Date(), "Set the name to Joe"));
      System.out.println("Name set to Joe!!");
      user.getProtienData().setGoal(250);
      user.addHistory(new UserHistory(new Date(), "Set the goal to 250"));
      System.out.println("Goal set to 250!!");
      session.save(user);
      System.out.println("Session saved");
  
      session.getTransaction().commit();
      System.out.println("Commit done - well done!!");
      System.out.println("Beginning transaction!");
  
      session.beginTransaction();
  
      User loadedUser = (User) session.load(User.class, 1);
      System.out.println("Name of user is " + loadedUser.getName());
      System.out.println("Number of goal is " + loadedUser.getProtienData().getGoal());
      for(UserHistory history : loadedUser.getHistory())
      {
          System.out.println(history.getEntryTime().toString() + " " + history.getEntry());
      }
  
      loadedUser.getProtienData().setTotal(loadedUser.getProtienData().getTotal() + 50);
      loadedUser.addHistory(new UserHistory(new Date(), "Added 50 protein"));
      System.out.println("Total of user is " + loadedUser.getProtienData().getTotal());
  
      session.getTransaction().commit();
      System.out.println("After commit, total of user is " + loadedUser.getProtienData().getTotal());
      session.close();
      HibernateUtilities.getSessionFactory().close();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My proteinData class is as follows:</p>
  
  <pre><code>package com.simpleprogrammer;
  public class ProtienData {
  
  private int total;
  private int goal;
  
  public int getGoal() {
      return goal;
  }
  public void setGoal(int goal) {
      this.goal = goal;
  }
  public int getTotal() {
      return total;
  }
  public void setTotal(int total) {
      this.total = total;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And my User.java file is: 
      package com.simpleprogrammer;</p>
  
  <pre><code>import javax.persistence.Entity;
  import javax.persistence.Id;
  import java.util.*;
  
  @Entity
  public class User {
  
      @Id
      private int id;
      private String name;
  
      private ProtienData protienData = new ProtienData();
  
      private List&lt;UserHistory&gt; history = new ArrayList&lt;UserHistory&gt;();
  
      public void addHistory(UserHistory historyItem) {
      historyItem.setUser(this);
      history.add(historyItem);
      }
      public ProtienData getProtienData() {
      return protienData;
      }
      public List&lt;UserHistory&gt; getHistory() {
      return history;
      }
  
      public void setHistory(List&lt;UserHistory&gt; history) {
      this.history = history;
      }
      public void setProtienData(ProtienData protienData) {
      this.protienData = protienData;
      }
      public int getId() {
      return id;
      }
      public void setId(int id) {
      this.id = id;
      }
      public String getName() {
      return name;
      }
      public void setName(String name) {
      this.name = name;
      }
  }
  </code></pre>
  
  <p>My UserHistory class is as follows: </p>
  
  <pre><code>package com.simpleprogrammer;
  import javax.persistence.Temporal;
  import javax.persistence.TemporalType;
  import java.util.Date;
  
  public class UserHistory {
  private int id;
  private User user;
  
  private Date entryTime;
  private String entry;
  
  public int getId() {
      return id;
  }
  public void setId(int id) {
      this.id = id;
  }
  public User getUser() {
      return user;
  }
  public void setUser(User user) {
      this.user = user;
  }
  
  
  public UserHistory(Date entryTime, String entry) {
      this.entry = entry;
      this.entryTime = entryTime;
  }
  public UserHistory() {
  }
  
  public Date getEntryTime() {
      return entryTime;
  }
  public void setEntryTime(Date entryTime) {
      this.entryTime = entryTime;
  }
  public String getEntry() {
      return entry;
  }
  public void setEntry(String entry) {
      this.entry = entry;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>One of my hibernate mapping file is as follows: (with the header etc removed)</p>
  
  <pre><code>&lt;class name="com.simpleprogrammer.UserHistory" table = "USERHISTORY"&gt;
  &lt;id name="id" type="int"&gt;
      &lt;column name="ID"  /&gt;
      &lt;generator class="increment"/&gt;
  &lt;/id&gt;
  &lt;many-to-one name="user" class="com.simpleprogrammer.User" not-null="true"&gt;
      &lt;column name="USER_ID" /&gt;
  &lt;/many-to-one&gt;
  &lt;property name="entryTime" type="java.util.Date"&gt;
      &lt;column name="ENTRYTIME" /&gt;
  &lt;/property&gt;
  &lt;property name="entry" type="java.lang.String"&gt;
      &lt;column name="ENTRY" /&gt;
  &lt;/property&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>and the other one is as follows: 
      
      
          
              
              
          
          
              
          </p>
  
  <pre><code>    &lt;component name = "protienData"&gt;
          &lt;property name="total" type="int"&gt;
              &lt;column name="TOTAL" /&gt;
          &lt;/property&gt;
          &lt;property name="goal" type="int"&gt;
              &lt;column name="GOAL" /&gt;
          &lt;/property&gt;
      &lt;/component&gt;
      &lt;list name = "history" table="USER_HISTORY" inverse="true" cascade="save-update"&gt;
          &lt;key column="USER_ID"/&gt;
          &lt;list-index column="POSITION"/&gt;
          &lt;one-to-many class="com.simpleprogrammer.UserHistory"/&gt;
      &lt;/list&gt;
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>I'm getting the following error when I try to run this:</p>
  
  <pre><code>Exception in thread "main" org.hibernate.exception.DataException: could not execute statement
      at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:71)
      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:136)
      at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:58)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3067)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3509)
      at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
      at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:369)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:286)
      at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:339)
      at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
      at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)
      at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
      at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
      at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
      at com.simpleprogrammer.Program.main(Program.java:21)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
  Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'ENTRYTIME' at row 1
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2868)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
      at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1169)
      at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:693)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1404)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1318)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1303)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133)
      ... 19 more
  </code></pre>
  
  <p>Does anybody know what is causing this> </p>