2 Replies Latest reply on Jul 30, 2010 9:18 AM by Walt Corey

    homogenious container owned data sources

    Walt Corey Newbie

      I have a problem I'd like help narrowing down a solution for. I have a Seam webapp that is very good at navigating a given data source's schema. This works out well as the seam-gen process builds the necessary linkage between the app and the container. However, there is one EntityManager that is injected into the various beans to process the various tables in the schema. I need to modify the program to dynamically allow that EntityManager injection to refer to one of any number of data sources. Each data source (logical database) has the identical schema. I'd like to avoid having 10 different EntityManagers defined.


      Thanks,


      Walt

        • 1. Re: homogenious container owned data sources
          Walt Corey Newbie

          To elaborate..
          There is a persistence.xml which links a PersistenceUnit name to a data source name such that when the EntityManager is injected it is tied to the related data source. What I'd like to do and am not sure I can, is keep the single PersistenceUnit name but, programmatically, link it to one of several data sources.


          foo1-ds.xml points to logicalDB1a
          foo2-ds.xml points to logicalDB1b
          foo3-ds.xml points to logicalDB1c


          the logicalDB1 series have the precisely identical table structure, just different data. This distinction (having multiple logical databases) is a business requirement. Rather than having, in this case, 3 versions of the program each with a different persistence.xml I'd like one instance of the program that starts with a selection menu for which database this run will be opening. Perhaps a single selection menubox or a radio button selection


          o FOO1
          o FOO2
          x FOO3


          and the rest of th3 beans will be identical to if they had but a single data source.

          • 2. Re: homogenious container owned data sources
            Walt Corey Newbie

            to further elaborate, I am ok with multiple persistent-units defined in the persistence.xml just so long as I can programatically control which one gets mapped to the Seam controller bean entityManager (or em) which logically represents that particular data source. I was hoping the answer would lie in chapter 8 or even 9 but I don't see a solution there.