Hi Florian,
I'm hoping you have a recommended approach for managing entities that can point to different instances of databases with a common schema. I'm using the BSLA code generation but the problem would probably have a wider audience. There is a base class in the code gen that depends on injection to define database connection:
public abstract class EotcGenericDaoJpaImpl <T extends AbstractDomainObject> extends GenericDaoJpaImpl<T> {
@PersistenceContext (unitName = "eotc")
protected EntityManager entityManager;
public EntityManager getEntityManager() {
return entityManager;
}
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
}
Is there a way to decide at runtime which db instance will be chosen? Seems there are several ways to get there but none seem too appealing. Can the EntityManager be overridden after instantiation but before any operations are performed? Can I replace the EntityManager midstream (for example read from one instance / swap / write to different instance? Seems inappropriate.
Please advise.