Cant get EJB create method to work inside another EJB
I am using EJB 3.0 and trying to create a customer record in the database using the following method in another session EJB:
customerFacade.create(cust);
I continue to get a null pointer error on the above line, even though I have established non null values for EVERY field in the customer table.
The only things I have not done a cust.set...() method for are the related object collections with one to many relationships (such as cust.setCustAddressCollection() ).
My code works when I put in a servlet, but does not work when I call it inside another EJB. Is there some reason it will not work in the EJB?
Here is the code in the session bean that does not work:
publicvoid registerCustomer(Customer cust, Address addr){
// Declare & instatiate the necessary objects
// set up Date
Date now =new Date();
//encrypt the password
String password = cust.getLogonpassword();
encryptionBean encrypter =new encryptionBean();
int salt = encrypter.getSalt();
String encryptedPass = encrypter.encryptIt(password, salt);
// Get next available Key & increment
KeyManagerBean custKey =new KeyManagerBean();
BigInteger customerId = custKey.getNextKey("customer");
BigDecimal bdSetter =new BigDecimal("0");
int intSetter = 0;
// add the additional necessary fields
try{
cust.setCustId(customerId);
cust.setLogonpassword(encryptedPass);
cust.setSalt(String.valueOf(salt));
cust.setRegistration(now);
cust.setLastsession(now);
cust.setPasswordcreation(now);
cust.setPasswordretries(0);
cust.setField1(intSetter);
cust.setField2(intSetter);
cust.setField3(intSetter);
cust.setField4(bdSetter);
cust.setField5("");
cust.setField6("");
cust.setField7("");
cust.setField8("");
cust.setField9("");
cust.setLastorder(now);
cust.setPasswordinvalid(now);
cust.setRegistrationupdate(now);
customerFacade.create(cust);
}catch (Exception e){
System.out.println("exception adding cust in CustomerMaintenanceBean: "+e);
}
}

