0 Replies Latest reply on Nov 19, 2009 10:36 AM by getaceres

    Getting persistence units programatically for JTA

    getaceres

      Hello, I'm developing an application and I have to use the same JPA beans in multiple databases in the same application. The solution that I've thought is to create various persistence units, one for every database and use them in my beans. The problem of this approach is that I cannot use the @PersistenceContext or @PersistenceUnit annotations since the persistence unit for those elements is fixed and I need to get it programatically. On every request I have to decide which database to use.
      I tried using the Persistence.createEntityManagerFactory call in my EJB but it fails because my datasource (and my persistence unit) are configured to use JTA and I get the error:

      Caused by: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager


      I could configure them as RESOURCE_LOCAL but I'm only going to use them in EJBs and I'd like to have automatic transaction management, and so, I want JTA.

      I don't know if that's possible. Has anybody managed to get it? Do I have to loose JTA?