0

私は CustomerEntity と ContactEntity と PointEntity を使用して EJB プロジェクトを行っています。顧客と連絡先には 1 対 1 の関係があり、顧客とポイントも同様です。しかし、顧客を作成するたびに、この例外がスローされます

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

事前に感謝します誰でも助けることができます!

4

0 に答える 0