4 Replies Latest reply on Jan 9, 2006 9:36 AM by boby

    Is it possible to connect at multiples databases ???

    boby

      Hello everybody,

      JBoss 4.0.3SP1
      EJB3 RC3

      I use the EJB3 persistance with one database. That is works. But actually I have one database by client. Therefore, I need to connect (disconnect) at multiples databases according to the client.
      For example :
      1) a client X asks to me a jobs list. I have to connect to database of client X.
      Then
      2) a client Y asks to me his jobs list. I have to connect to database of client Y.
      etc.. for every client.

      I dont know how to do. I looked at wiki, forum.
      I think it has to do some modifications in datasource, then the look up in EJB Session and specify the database name for example.

      Have you any suggestions ???

        • 1. Re: Is it possible to connect at multiples databases ???

          are you accessing the database via entity beans?

          • 2. Re: Is it possible to connect at multiples databases ???
            boby

            I access the database with the Entity Manager like this :

            @PersistenceContext(unitName = "jobs")
            protected EntityManager em;

            public Collection<T_Jobs> getJobs() {
            return em.createQuery("from T_Jobs").getResultList();
            }

            for example to retrieve the jobs, but Id like to do that on the database which I want.
            I think at a solution, but I have to create a file -ds.xml fro each database (hence for each client). Then I have to write the list of -ds.xml file in my persistence.xml file.

            I would have a number of fix database, that would be great, but that changes everytyme. Therefore, I have to find a best mean.

            • 3. Re: Is it possible to connect at multiples databases ???

              a datasource file (ds.xml) can contain references to multiple databases/datasources.

              jboss-dtd_1_5.dtd:

              <!ELEMENT datasources (mbean | local-tx-datasource | xa-datasource | no-tx-datasource | ha-local-tx-datasource | ha-xa-datasource)*>

              you would need to link each to client to each datasource.

              hope this helps :-D

              • 4. Re: Is it possible to connect at multiples databases ???
                boby

                I know it, thanks anyway. :=)

                Im trying to implement the ConnectionProvider interface Hibernate for using my connection pool with my databases. I have to know now how to update dynamically the entityManager with my ConnectionProvider. I cant use the @PersistanceContext annotation, I think.

                Im going to look at this.

                Thanks.