[jpa-spec issues] [JIRA] Commented: (JPA_SPEC-17) Dynamic persistence unit
- From: "c.beikov (JIRA)" <
- Subject: [jpa-spec issues] [JIRA] Commented: (JPA_SPEC-17) Dynamic persistence unit
- Date: Wed, 24 Apr 2013 16:39:58 +0000 (UTC)
- Auto-submitted: auto-generated
c.beikov commented on JPA_SPEC-17:
Adding a new persistence unit is kind of tricky with the current state of the
API. This is currently only possible my managing the EMFs within the
application but you probably also have to depend on some code of the
underlying persistence provider to do the dynamic configuration of the EMF.
Transaction Management and so on could be handeled by using the new
transaction interceptors of Java EE 7(at least I think that it would be
possible, not sure about that). It is possible but not entirely with the
standards provided by JPA.
The requirement was to switch PUs but not the underlying datasource of a PU.
So when you know at deployment time what PUs you have you can do it like that.
I could still think of something else, but this is probably the worst
solution. You could set a comment hint on every query you execute, let the
address of the PUs database point to a proxy that does the selection by
inspecting the comments.
> Dynamic persistence unit
> Key: JPA_SPEC-17
> URL: https://java.net/jira/browse/JPA_SPEC-17
> Project: jpa-spec
> Issue Type: New Feature
> Reporter: likenootherufo
> Assignee: ldemichiel
> Without changing code and redeploying my application, I need to be able to
> switch persistence units in some of my EJBs based on client connected to
> It is similar to multitenancy, but whereas there a single DB is divided
> into equal shares and shared between multiple tenants, here a single tenant
> wants multiple DBs appearing as a single one.
> During runtime based on the client connected to the EJB, the specific
> database should be selected.
> Currently I achieve this using JDBC connections and just changing the
> database connection details based on client connected.
> The database connection details are stored in the main system database and
> retrieved when the client connects.
> This allows the system to grow with ease as new client databases can be
> created on the fly and simply linked to the client
> in the database.
> Ideally I would like to dynamically add new persistence units to the system
> (persistence.xml) and then in my database
> link these persistence units to a given client. When the client connects,
> the system loads the required persistence unit.
This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see: http://www.atlassian.com/software/jira