3 Replies Latest reply on Oct 22, 2007 5:39 PM by Ajay Das

    Dynamic user for database connection

    Nicklas Karlsson Master

      Hi,

      There is the DataSource.getConnection(username, password) but when using JPA, is there any way of doing a run-time change of the database user? EntityManagerFactory has a setPersistenceUnitProperties(Map) but that is probably at too high a level(?)

        • 1. Re: Dynamic user for database connection
          Pete Muir Master

          Probably ask this in the hibernate forum.

          • 2. Re: Dynamic user for database connection
            Jose Rubio Newbie

            I had to do something along the same lines, where my database information was specific to each user logging in.

            What I ended up doing was implementing my own Persistence Context manager and that object got a User object injected that had some database information then on the getEntityManager I would create my own datasource and used the HibernatePersistence API directly. Then in the entity class I would specify the component to use when injecting the EntityManager.

            Let me know if this is what you want I can post an example.

            • 3. Re: Dynamic user for database connection
              Ajay Das Newbie

              Hello Wiberto, I would need to do something similar, where I would need to make a user specific connection to Oracle when the user logs in to the application. Can you please post the relevant pieces of code ? Thx in advance !


              "wiberto" wrote:
              I had to do something along the same lines, where my database information was specific to each user logging in.

              What I ended up doing was implementing my own Persistence Context manager and that object got a User object injected that had some database information then on the getEntityManager I would create my own datasource and used the HibernatePersistence API directly. Then in the entity class I would specify the component to use when injecting the EntityManager.

              Let me know if this is what you want I can post an example.