I have been following the affableBean tutorial from the NetBeans site located here .
Code Repo here .
I have run into an issue where I am unable to submit a purchase order(checkout.jsp).
When I submit the form data, I receive an http 500 status and the following errors:
WARNING: EJB5184:A system exception occurred during an invocation on EJB OrderManager, method: public java.util.Map session.OrderManager.getOrderDetails(int)
WARNING: javax.ejb.EJBException at controller.ControllerServlet.doPost(ControllerServlet.java:184)
Caused by: java.lang.NullPointerException at session.OrderManager.getOrderDetails(OrderManager.java:111)
Line 184 of ControllerServlet is: Map orderMap =
orderManager.getOrderDetails(orderId);Line 111 of OrderManager is: Customer customer = order.getCustomer();
While running a debug session, it seems that the culprit is the line in OrderManger inside the getOrderDetails() method. From what I can tell,the line is supposed to populate the customer object with the orders’ customer.
Looking into where the .getCustomer() method originates it is from the CustomerOrder Entity class:
private Customer customer;
...
public Customer getCustomer() {
return customer;
}
Seems simple enough, it returns the Customer object. What is puzzling me is why I would receive a nullpointer exception, why is this object empty?
I believe it may be down to my entity class being incorrect, this in turn would mean my database that I forward engineered from a entity diagram would be incorrect, am I on the right path?
Edit:
Having removed the try catch block from the placeOrder() method within the ordermanager class
due to it modifying the return value to 0.
i have run into additional problems:
WARNING: EJB5184:A system exception occurred during an invocation on EJB OrderManager, method: public int session.OrderManager.placeOrder(java.lang.String,....,cart.ShoppingCart)
WARNING: javax.ejb.EJBException
javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'.**
at session.OrderManager.addCustomer(OrderManager.java:58) (*em.persist()*)
at session.OrderManager.placeOrder(OrderManager.java:42) (*Customer customer = addCustomer()*)
I am currently reading up on how to iterate over the errors and find what constraint i am failing.
Edit2:
Debugging the addCustomer method i see the customer id is null, is this okay? i assume it is as the ID database field is set to auto-increment, still, seems odd to have an settable id field in the entity at all in that case.
Edit3:
Turns out the auto generated [NotNull] tags in my entity classes were causing bean validation to fail, removed the tags and it works fine.
The only possible cause that I see for a NPE thrown there, is that
orderitself is a null object.Since order is given by:
my conclusion is that an order with that
orderIdis simply not present in the db.