[jboss-user] [EJB3] - Field 'record_EMP_ID' doesn't have a default value

Joseph Hwang do-not-reply at jboss.com
Wed Aug 17 19:57:04 EDT 2011


Joseph Hwang [http://community.jboss.org/people/aupres] created the discussion

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

To view the discussion, visit: http://community.jboss.org/message/621434#621434

--------------------------------------------------------------
I solved org.hibernate.TransientObjectException (http://community.jboss.org/thread/171019?tstart=0) 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*


@Entity
@Table(name = "family")
public class Members implements Serializable {
  @Id
  @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 (http://community.jboss.org/mailto:%7B@JoinColumn(name) = "EMP_Name")})
  private Collection<Records> record = new ArrayList();
   ....getter and setter
}


*- Records.java*

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

  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  @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();
r.setName("aaa");
r.setAccount("111-2222");
r.setHobby("bbb");
r.setPhone(021112222);

Members m = new Members();
m.setId("aupres");
m.setPasswd("aaa");
m.setName("ccc");
m.getRecord().add(r);

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!
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/621434#621434]

Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110817/f224faa5/attachment.html 


More information about the jboss-user mailing list