I don't see any obvious mistake here (are you sure that you don't call Controller2#getShoppingCart()
before adding any items do your CartDAO
?) but here are couple of my notions
- you should have your
CartDAO
implement some interface or make it@LocalBean
- all stateful beans should have method annotated with
@Remove
so you can clean the resources used in the bean (close datasources and son) and bean will be removed from the memory after this call - now it's recommended to use
@Inject
everywhere instead of@EJB
, it's the same (you have to use@EJB
only when you inject remote beans)
And also one point, if the System.out.println(cartDao.getCart());
returns null than it means the @PostConstruct
haven't been called which is strange. Can you provide some more info about container and your environment?Also show us imports, this is big source of mistakes.