I have a web module and an ejb module packaged into an EAR.
I have JSF backing beans successfully injecting Session EJBs from from the ejb module which are able to pull data from the DB, E.g.
@RequestScoped
public class CarController {
@EJB
private CarService carService;
To support Primefaces LazyDataModel, the session EJB exposes it's EntityManager to a LazyDataModel:
@PostConstruct
public void init() {
MyLazyDataModel<Car> myLazyDataModel = new MyLazyDataModel<Car>();
myLazyDataModel.setEntityManager(carService.getEntityManager());
super.setMyLazyDataModel(myLazyDataModel);
}
This causes the follow exception:
java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:132)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:173)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.getCriteriaBuilder(EntityManagerWrapper.java:895)
at com.cars.web.controller.MyLazyDataModel.load(MyLazyDataModel.java:154)
at org.primefaces.component.datatable.DataTable.loadLazyData(DataTable.java:731)
Is this not working because the PersistenceContext is only a valid bean to pass around within the ejb module?