0 Replies Latest reply on Aug 17, 2011 7:53 AM by Joseph Hwang

    Field 'record_EMP_ID' doesn't have a default value

    Joseph Hwang Novice

      I solved org.hibernate.TransientObjectException by adding "@OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL)"

      But this time values can't be inserted to DB.


      OS : Windows 7 

      JDK : JDK 1.6
      JBoss : JBoss 5.1.0.GA
      DB : MySQL 5.5




      Error is "Field 'record_EMP_ID' doesn't have a default value"



      - Members.java



      @Table(name = "family")
      public class Members implements Serializable {
        @Column(name = "EMP_ID")
        private String id ;


        @Column(name = "EMP_Passwd")
        private String passwd ;


        @Column(name = "EMP_Name")
        private String name ;

        @OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
        @JoinTable(name="info", joinColumns = {@JoinColumn(name = "EMP_Name")})
        private Collection<Records> record = new ArrayList();

         ....getter and setter




      - Records.java


      @Table(name = "info")
      public class Records implements Serializable {

        @Column(name = "EMP_ID")
        private int i;

        @Column(name = "EMP_Name")
        private String name;


        @Column(name = "EMP_Bank_Account")
        private String account;


        @Column(name = "EMP_Hobby")
        private String hobby;


        @Column(name = "EMP_Phone")
        private int phone;

        ...getter and setter method




      in jsp file I invoke EntityManager.persist




      Context ctx = new InitialContext();
      IMappingTestPort port = (IMappingTestPort) ctx.lookup("MappingTestBean/remote");

      Records r = new Records();

      Members m = new Members();

      port.setFamilyMember(m); // This EntityManager.persist method



      But it failed.

      In console

      20:21:29,233 INFO [STDOUT] Hibernate: insert into family (EMP_Name, EMP_Passwd, EMP_ID) values (?, ?, ?)
      20:21:29,268 INFO [STDOUT] Hibernate: insert into info (EMP_Bank_Account, EMP_Hobby, EMP_Name, EMP_Phone) values (?, ?, ?, ?)
      20:21:29,288 WARN [JDBCExceptionReporter] SQL Error: 1364, SQLState: HY000
      20:21:29,288 ERROR [JDBCExceptionReporter] Field 'record_EMP_ID' doesn't have a default value


      record_EMP_ID is automatically generated by hibernate


      Pls help!