1 Reply Latest reply on Aug 23, 2005 12:00 PM by yangju

    JBoss, Hibernate, Connect to multiple datasources?

    yoava

      I am tring to build an application that visualises data from one of several possible databases. I want to have an MBean that allow to make a datasource, hibernate sessionFactory connected to it, and have a website with the data.

      I have found how to register a datasource, by copying a xxx-ds.xml file in the JBoss deploy folder.

      How can I create a Hibernate sessionFactory on the fly?

      The only way I know to make sessionFactory in JBoss is using a HAR archive, and this is static, not dynamic.

      Thanks, Yoav.

        • 1. Re: JBoss, Hibernate, Connect to multiple datasources?
          yangju

          I am facing the same problem. I cannot find a good solution. But to get around with this, I had to dynamically clone an existing hibernate sevice mbean (using MBeanServer API) and modify the datasource attribute of the created mbean on the fly. I keep all other attributes untouched (ofcouse you need to assign a unique jmx objectname for this newly created mbean). This way, I only need to define one sessionfactory mbean for one database and create sessionfactories for other datasources on the fly.
          I don't think this is the best solution because if you bounce your jboss server, all the dynamically generated sessionfactories will be lost. But this approach works.
          Anybody has better idea? The problem facing us is that we only know which datasource to call at runtime. And we don't want to hard code the hibernate session factory.