12 Replies Latest reply on Sep 14, 2007 4:52 AM by Olivier Vincent

    Dynamic data sources with EntityManager

    Jose Rubio Newbie

      I have an application where the data source it uses is saved in the database. This is because each user can have its own data source.

      So UserA will have an entry in it's user information table that says to use data source jdbc/UserA.

      Lets assume that this entry is already configured in the app server itself.

      How do I tell the EntityManager at runtime to use that datasource.

      If this was a static configuration I know I will have the persistence unit defined in my persistence.xml file and I would set the annotation in my entity. Something like this

      private EntityManager em;

      So how do I make this generic? Do I need to override any EntityManager API to be able to select the unitName at run time? Also, can I create persistence units on the fly?

      Thanks in advanced,