我正在使用CustomerEntity和ContactEntity以及PointEntity进行EJB项目,客户和联系人具有一对一的关系,客户和点也是如此。但每次我想创建一个客户时,都会抛出此异常
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: column “CUSTOMERID”cannot accept null value
Error Code: -1
Call: INSERT INTO CUSTOMER (CUSTOMERID, NAME, PASSWORD, CONTACT_CONTACTID, POINT_POINTID) VALUES (?, ?, ?, ?, ?)
bind => [5 parameters bound]
会话bean中的方法如下:
@Override
public void registerCustomer(String customerId,String name,String password,String addr,String phone,String email) throws EntityExistsException{
System.out.println("register Custoemr begins");
customerEntity= em.find(CustomerEntity.class, customerId);
if (customerEntity != null){
System.out.println("customer already exists!");
throw new EntityExistsException();
}
customerEntity=new CustomerEntity();
System.out.println("new customer created");
String hashword = null;
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(password.getBytes());
BigInteger hash = new BigInteger(1, md5.digest());
hashword = hash.toString(16);
} catch (NoSuchAlgorithmException nsae) {
}
System.out.println("info read is id "+customerId+" name:"+name+" password:"+password+" addr:"+addr+" phone:"+phone+" email:"+email);
customerEntity.create(customerId, name,hashword);
ContactEntity contact=new ContactEntity();
contact.create(addr, phone, email);
System.out.println("contact created");
PointEntity point=new PointEntity();
point.create(0);
System.out.println("point created");
customerEntity.setContact(contact);
customerEntity.setPoint(point);
System.out.println("set contact and point");
System.out.println("create succesful");
em.persist(customerEntity);
System.out.println("after persist");
}
这是我的主要内容:
else if(input==5)
{System.out.println("create customer: enter id ");
String id=sc.next();
System.out.println("enter name");
String name=sc.next();
System.out.println("enter password");
String password=sc.next();
System.out.println("enter addr");
String another=sc.nextLine();
String addr=sc.nextLine();
System.out.println("enter phone and email");
String phone=sc.next();
String email=sc.next();
b.registerCustomer(id,name,password,addr,phone,email);
System.out.println("after register");}
提前致谢,任何人都可以提供帮助!