I need a way to dynamically specify the persistence unit in a EJB.
Simplified example:
I have an application using multiple databases as data stores. Each of the data stores are structurally the same. Depending on the client connecting to the application I need to access the data from a specific data store.
Therefore, I would like to use the same EJB so that the business logic is not duplicated, but then just select the correct persistence unit based on the client.
Up to this point I've only directly injected the entity manager with the persistence unit name hard coded. Is there a way I can dynamically inject the entity manager with the required persistence unit attached to the EJB? Also, can persistence units be added dynamically during runtime? I currently have to specify the persistence unit in the persistence.xml file. Ideally I would like to create pools on the server jdbc/db1, jdbc/db2 etc as required while the system is running. Then just add these to the central client database and link it to a client, so that when the client connects, it will check the name of the pool, and use it when calling the EJB to get the persistence unit.
I'm still really new to Java EE development. Any help would be greatly appreciated.