HI,
I have a class Customer and Vehicle. Fist a customer needs to be added to the application. when a vehicle is being added the customer id needs to be added also
so i wrote the code as below
@Override
public void addVehicle( String make, String model, String year, String reg, String vin, String miles,String cid) {
Vehicle v = new Vehicle();
//v.setVehicleid(id);
v.setMake(make);
v.setModel(model);
v.setVehicleyear(Integer.parseInt(year));
v.setRegno(reg);
v.setVin(vin);
v.setMiles(Integer.parseInt(miles));
Customer c;
try{
**c = customerService.findCustomer(cid);**
v.setCusid(c);
}
catch(Exception e)
{
System.out.printf("error " + e.toString());
}
entityManager.persist(v);
}
the line which is bold throws an null point exceptoin. i searched for the reason it says if there is no record in the db it will throw a nullpointer exception. but i have a record in the db.
what could be the reason ?
@PermitAll
public Customer findCustomer(String customerID) {
return entityManager.find(Customer.class, customerID);
}
appreciate a reply
thanks