|Parameterized PersistenceContext in EJB 3.1 [message #733664]
||Wed, 05 October 2011 06:57
| Wladimir Kral
Registered: June 2011
I have an environment with a single application server and a single database for several different dealer environments. The application is for all the same and every dealer has its own database schema.|
OS400 DB2 Datebase:
In the current solution there is a separate datasource and a separate EntityManagerFactory for each dealer preset with his schema.
Now I want to migrate the solution from Java SE to EJB 3.1.
To something like this sample below:
public class VehicleBean
@PersistenceContext(unitName = "Dealer")
private EntityManager em;
public Vehicle getVehicle(int dealerId, int vehicleId)
.. // ??? code to configure entity manager to use the database schema/datasource of the dealer
My ideas so far:
- Ignore dependency injection and use the approach as in Java SE. (drawback: I will not get the benefits of container managed persistence context and transactions)
- Unwrap ServerSession in Stateless Bean method and set current schema for the datasource. (drawback: makes the second level cache unusable since all entities from the different dealers will be mixed together)
- Use a SessionBroker with a separate ServerSession for each dealer. But I do not know how to use it in JPA/EJB context.
Can you help me to solve the problem?
Powered by FUDForum
. Page generated in 0.09570 seconds