having this generic DAO definition

public class GenericService<T> implements IGenericService<T> {
    @PersistenceContext(unitName="mgrUnit", name="mgrEMF")
    @Qualifier(value = "mgrEMF")
    public void setEm(EntityManager em) {       
        this.em = em;       
        util = em.getEntityManagerFactory().getPersistenceUnitUtil();       

and having a large number of Entities, i want to automatiqualy instanciate DAO, Back-End Beans for basic tables like ( Region, EmployeSpeciality... )

For the bean registration and instantion it's easy but what about the DAO ? I must precise that in my case the EntityManager depends on the service, i have a multiple Database connection.

i read this article but honnestly it looks to much complicated

Is there a simple way to do it ?

OK, using

AutowireCapableBeanFactory beanFactory = 

It solve the half of the problem, the Bean EMF is correctly injected, but the bean is not registred (i must re-instanciate it every time i need), because the beanFactory doesnt contains the Bean Definition, so how to add it?

NB: i know that puting the object in the application MAP can keep the DAO accessible but its not a serious solution

            getApplicationMap().put( serviceName, service);
Était-ce utile?

La solution

IGenericService service = (IGenericService) ContextManager.findBean( serviceName );     
if (service==null && !FacesUtils.getWebappContext().getBeanFactory().

   service = new ErpGenericService(clazz);
   AutowireCapableBeanFactory beanFactory = FacesUtils.getWebappContext().
   //Applying transactional proxies
   service = (IGenericService) beanFactory.applyBeanPostProcessorsAfterInitialization(service, serviceName);
                     registerSingleton(serviceName, service);                       

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow