title: ERROR org.hibernate.util.JDBCExceptionReporter - Data truncated for column 'type'
body: <p>I am new to Hibernate and working on a test project, I have tried a lot of things to get this example working. But I am unsure why it fails, I am aware that the null pointer exception could be because I am trying to getQuestions on Survey but its empty. But I have seen so many tutorials online and followed them and all have the same approach. I have tried recreating the database tables, different versions of hibernate. Nothing has helped me get this resolved. If someone can take a look and guide me would be great help. I would appreciate your feedback. Also if I comment out the question part in Application.java then the survey object gets inserted in the database. I am not sure why the questions fail and don't get insert.Please guide me.</p>
  
  <p>This is my First model class:</p>
  
  <pre><code>@Entity
  @Table(name="question")
  public class Question implements java.io.Serializable{
  
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue
  @Column(name = "id")
  private Long _id;
  
  @Column(name = "label")
  private String _label;
  
  @Column(name="type")
  private QuestionType _type;
  
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name="survey_id")
  private Survey _survey;
  
  public Question() {
  }
  
  public Question(final Long id, final String label, final QuestionType type, final Survey survey,final Long surveyId) {
      _id = id;
      _label = label;
      _type = type;
      _survey = survey;
  
      Assert.notNull(_id, "_id cannot be null");
      Assert.notNull(_label, "_label cannot be null");
      Assert.notNull(_type, "_type cannot be null");
      Assert.notNull(_survey, "_survey cannot be null");
  }
  
  public Long getId() {
      return _id;
  }
  
  public void setId(Long id) {
      _id = id;
  }
  
  
  public String getLabel() {
      return _label;
  }
  
  public void setLabel(String label) {
      _label = label;
  }
  
  
  public QuestionType getType() {
      return _type;
  }
  
  public void setType(QuestionType type) {
      _type = type;
  }
  
  public Survey getSurvey() {
      return _survey;
  }
  
  public void setSurvey(Survey survey) {
      _survey = survey;
  }
  
  @Override
  public String toString() {
      return "Question [_id=" + _id + ", _label=" + _label + ", _type="
              + _type + "]";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is my second model class:</p>
  
  <pre><code>@Entity
  @Table(name="survey")
  public class Survey implements java.io.Serializable{
  
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue
  @Column(name = "survey_id")
  private Long _id;
  
  @OneToMany(fetch = FetchType.LAZY, mappedBy = "_survey")
  private List&lt;Question&gt; _questions ;
  
  @Column(name="name")
  private String _name;
  
  public Survey() {
      super();
      _questions = new ArrayList&lt;Question&gt;();
  }
  
  public Survey(Long id, List&lt;Question&gt; questions, String name) {
      super();
      _id = id;
      _questions = questions;
      _name = name;
  
      Assert.notNull(_id, "_id cannot be null");
      Assert.notNull(_questions, "_questions cannot be null");
      Assert.notNull(_name, "_name cannot be null");
  }
  
  public Long getId() {
      return _id;
  }
  
  public void setId(Long id) {
      _id = id;
  }
  
  
  public List&lt;Question&gt; getQuestions() {
      return _questions;
  }
  
  public void setQuestions(List&lt;Question&gt; questions) {
      _questions = questions;
  }
  
  
  public String getName() {
      return _name;
  }
  
  public void setName(String name) {
      _name = name;
  }
  
  @Override
  public String toString() {
      return "Survey [_id=" + _id + ", _questions=" + _questions + ", _name="
              + _name + "]";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is my application class:</p>
  
  <pre><code>public class Application {
  
  public static void main(String[] args) {
  
  
      System.out.println("Hibernate one to many (Annotation)");
      Session session = HibernateUtil.getSessionFactory().openSession();
  
      session.beginTransaction();
      Survey survey = new Survey();
      survey.setName("Ice Cream final");
      session.save(survey);
  
  
      Question question1 = new Question();
      question1.setLabel("Whats your favorite Ice Cream");
      question1.setType(QuestionType.TEXT);
      question1.setSurvey(survey);
      survey.getQuestions().add(question1); 
      session.save(question1);
  
      session.getTransaction().commit();
      System.out.println("Done");
  
   }
  </code></pre>
  
  <p>Hibernate Util Class:</p>
  
  <pre><code>public class HibernateUtil {
  private static final SessionFactory sessionFactory = buildSessionFactory();
  
  private static SessionFactory buildSessionFactory() {
      try {
          // Create the SessionFactory from hibernate.cfg.xml
          return new AnnotationConfiguration().configure().buildSessionFactory();
      } catch (Throwable ex) {
          // Make sure you log the exception, as it might be swallowed
          System.err.println("Initial SessionFactory creation failed." + ex);
          throw new ExceptionInInitializerError(ex);
      }
  }
  
  public static SessionFactory getSessionFactory() {
      return sessionFactory;
  }
  
  public static void shutdown() {
      // Close caches and connection pools
      getSessionFactory().close();
  }
  }
  </code></pre>
  
  <p>Hibernate config :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
  &lt;session-factory&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/xxxx_survey&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="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
      &lt;mapping class="xxxx.Survey" /&gt;
      &lt;mapping class="xxxx.Question" /&gt;
  &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Pom.xml has the following dependency:</p>
  
  <pre><code>    &lt;!-- MySQL database driver --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.1.6&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-annotations&lt;/artifactId&gt;
          &lt;version&gt;3.5.0-Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
          &lt;version&gt;1.7.5&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-simple&lt;/artifactId&gt;
          &lt;version&gt;1.7.5&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;javassist&lt;/groupId&gt;
          &lt;artifactId&gt;javassist&lt;/artifactId&gt;
          &lt;version&gt;3.12.1.GA&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>This is the error:</p>
  
  <pre><code>Hibernate: insert into survey (name) values (?)
  Hibernate: insert into question (label, survey_id, type) values (?, ?, ?)
  [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 1265, SQLState: 01000
  [main] ERROR org.hibernate.util.JDBCExceptionReporter - Data truncated for column 'type' at row 1
  Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert:    [xxxx.model.Question]
  at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
  at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
  at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
  at   org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
  at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2329)
  at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2836)
  at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
  at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)
  at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
  at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
  at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
  at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
  at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
  at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
  at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
  at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
  at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
  at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)
  at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)
  at xxxx.Application.main(Application.java:38)
  Caused by: java.sql.SQLException: Data truncated for column 'type' at row 1
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
  at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
  at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
  at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
  at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
  at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019)
  at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937)
  at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922)
  at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
  at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
  ... 16 more
  </code></pre>