Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Switch schema at runtime in a Container Managed Environment

918202Feb 17 2012 — edited Feb 17 2012
Need help on how to efficiently switch between schema's (or persistence-context) at run-time in a Container Managed Environment.The JPA is outside the EJB and hence we do not inject the EntityManager via the Container.

Business Model
---------------------
There are 4 Business Model Entities in the application - Users, Department,UserDepartment and Company

The Biz Case
------------------
The application has 'n' Database instances that represent 'n' regions. All the DB instances has the same DB Objects. (There is no difference in structure for any of the instances).
User can select a region from the UI and the application should load/save data from the database instance that represents that region.

Tech - Our approach
-----------------------------
We use JPA as the Persistence layer to achieve the ORM model with the database.
Since the tables are same in all the DB instances, we have n different persistence units in the persistence.xml
(The DB instances have same structure,hence the same entity classes are used irrespective of which schema its connected to.)
At run time, we need to create (or load as I'm not sure) the EntityManager for dealing with persisting/retreiving the Entity object.
This approach helps us to only edit the persistance.xml file next time, we add a new DB instance for a new Region.

Dilemma
-----------
We use SessionBeans in the Busineess tier to handle the user requests and then in turn delegate the operation request to the EntityDAO layer to
1. Load/Create the Entity Manager
2. Perform the load/persist operation on the JPA layer (via the EntityManager)
The Session Beans use CMT(Container Managed Transaction) and hence we do not make use of any Transaction(or UserTransaction) in the JPA layer.
We have noticed that while having this approach, the entity is not persisted into the Database.
We know that if the EntityManager is (Container) injected into the session bean, things work out.But in this approach, we do not have the flexibility to shift between the schemas that the user would want depending on the selected region.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 16 2012
Added on Feb 17 2012
5 comments
1,556 views