[jboss-user] [Persistence] - Re: how to create PersistenceUnit and map to dataSource prog

getaceres do-not-reply at jboss.com
Fri Nov 20 04:14:08 EST 2009


I have the same problem as you. I need to use different databases with the same tables in the same application (the difference is that for me is that redeploying or even restarting JBoss is permitted, but in this case, it doesn't matter).

The idea is to use the same persistence unit changing only the datasource that they use, so the name of the persistence unit can be the same (I think, somebody correct me if I'm wrong). The name has to be defined in persistence.xml because it's mandatory in JPA as well as a default datasource. Then, you can use the Persistence.createEntityManagerFactory method passing it:

- The name of the unit that you gave in persistence.xml
- javax.persistence.jtaDataSource or javax.persistence.nonJtaDataSource properties pointing to the JNDI address of the datasource that you want to use,  previously configured with access to your database. The case here (and the problem for me) is that I cannot use a JTA datasource, so I don't know why the property is there. 

Anyway. I havent's tested it deeply but in theory, this should work.

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

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



More information about the jboss-user mailing list