[jboss-user] [Persistence] - Getting persistence units programatically for JTA

getaceres do-not-reply at jboss.com
Thu Nov 19 10:36:30 EST 2009

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?

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4266582#4266582

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4266582

More information about the jboss-user mailing list