2 Replies Latest reply on Sep 7, 2010 6:30 PM by lelleh

    Dynamic Dependency Injection?

    agohar

      Hi,

       

      Is there a way to dynamically inject resources to stateless ejbs? I am writing Ejb which needs dynamic injection of EntityManager. I've got same table/Entity in two databases so depending on the Input, I need to decicide which Persistence Context to use. I've defined two persistence units in my persistence.xml. So e.g. if request type is 'A' then I need to use persistence Unit 'ADB' and if request type if 'B' I need to use 'BDB'. I know I can have both entity managers injected to my Ejb and then use an if everywhere I use entity manager to check the request type and use that entity manager. I was thinking to somehow dynamically inject the entity manager to ejb if thats possible?

       

      Thanks