Hi,
since the JBoss EJB3 forum didn't help, I am asking my question here - in particular because Hibernate's proprietary EntityManager API might help.
Although I would assume that what I'm trying to achieve is a rather common problem, I am still struggling with how to solve it in EJB 3.
I would like to be able to define separate database "realms" for an application which can be used in parallel. The application is based on EJB3 EntityBean POJOs. Here, I define "realm" as a place to which the data model is persisted, i.e. the same model should be persistable to different databases depending on the context of an access.
For example, I'd like to be able to say
- store all stuff in data source java:/some-mysql-database for the context "realm 1" and
- store all stuff in data source java:/some-oracle-database for the context "realm 2"
all within the same running JBoss instance.
On the DAO side my approach is to
- encode the context inside the principal of (authenticated) accesses (all accesses are necessarily authenticated)
- intercept calls using standard EJB3 interceptors which provide injection of a context-dependant EntityManager on a per-call basis.
Implementing the above approach requires the configuration of a separate persistence unit per context. What I'm currently lacking is a way to programmatically configure the persistence unit/EntityManagerFactory from a default "template" while overriding the data source.
I found this
http://www.jboss.com/index.html?module= ... ic&t=82781 which doesn't sound very encouraging. If the data source cannot be overridden, configuration becomes considerably harder because of the necessity to mangle the persistence.xml if a new context is to be configured.
Now I'm wondering whether what I'm trying to do is really that exotic or maybe if problems of this class are supposed to be tackled in a completely different way.
Thanks in advance
Joerg Henne