Skip to main content

Is it possible to have a "dynamic" @PersistenceContext?

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2003-11-13


I have a webapp using GlassFish3.1.1 + JSF2.1 + RichFaces4.3.2 + CDI/Weld + CODI + JPA2 + Hibernate4.2.2 + Firebird.
I use also JTA (database connection injection from GlassFish).

I need to install many clients with separate databases in a cloud server. My actual solution is to deploy 1 webapp per client.
Each webapp consumes +/- 300 Mb of RAM. Then, if I have a cloud server with 2 Gb, I get to deploy 5 webapps.

I would like to deploy just one webapp, and, after "an analysis of the user to log on", to use the database of his enterprise.
Then, I would have much more clients than actual 5.

My solution can't use some kind of multitenancy, because each client must have a separate database, it's a major pre-requisite.

My big problem is @PersistenceContext(unitName="XXX"), because XXX is defined statically, I don't get to change XXX after "an analysis of the user to log on".

Is there some way to do this?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-11-13