Hi. We have the following structure:
public class SomeClass {
@Inject private DaoFactory factory;
...
}
@ApplicationScoped
public class DaoFactory {
@Inject
private Instance<EntityManager> entityManagers;
...
}
@ApplicationScoped
@Alternative
public class TestEntityManagerProducer {
@Inject
private EntityManagerFactory factory;
@Produces
public EntityManager produceEntityManager() {
return factory.createEntityManager();
}
public void disposeEntityManager(@Disposes EntityManager em) {
em.close();
}
}
SomeClass is a client that used a application scoped DAOFactory to create DAO instances. The factory has an EntityManager injected that is produced by TestEntityManagerProducer.produceEntityManager() and the EntityManagers are dependent. There also exists a disposer method.
1. I assume, and this is what I observe, that by using Instance<EntityManager> (EM being a dependent instance), whenever I call Instance<>.get() I get a fresh EM instance. Is this correct? Is this a valid use case for the build-in Instance<> bean?
2. On which bean instance are the @Dependent EntityManager dependent on? On the bean that produced them or on the bean that has them injected?
3. I noticed that the disposer method for EntityManagers is not called when the application shuts down. I found this issue: https://jira.jboss.org/jira/browse/WELD-466. Is this the same one?
Regards,
wujek