Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
EJB项目:java.sql.SQLIntegrityConstraintViolationException_Java_Sql - Fatal编程技术网

EJB项目:java.sql.SQLIntegrityConstraintViolationException

EJB项目:java.sql.SQLIntegrityConstraintViolationException,java,sql,Java,Sql,我正在做一个带有CustomerEntity、ContactEntity和PointEntity的EJB项目,customer和contact有一对一的uni关系,customer和point也是这样。但每次我想创建一个客户时,它都会抛出这个异常 Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.Datab

我正在做一个带有CustomerEntity、ContactEntity和PointEntity的EJB项目,customer和contact有一对一的uni关系,customer和point也是这样。但每次我想创建一个客户时,它都会抛出这个异常

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");}

提前感谢是任何人都可以帮助的

该错误表示在插入期间未向CUSTOMERID字段传递任何值。CUSTOMERID字段是数据库不接受空值。非常感谢您的回复!但大体上,我要求用户输入customerid,然后将customerid传递给方法registerCustomer,为什么会变为null?这行是否打印所有值System.out.println(“信息读取为id”+customerid+”名称:“+名称+”密码:“+密码+”地址:“+地址+”电话:“+电话+”电子邮件:“+电子邮件”);您是否已将(?)的所有值传递到此sql查询中,并插入到客户(CUSTOMERID、姓名、密码、联系人ID、点ID)值(?、、、?、?)