I have an ear that use a datasource (for a JPA persistence unit).
Now I need to deploy multiple versions of this ear in the same jboss, each pointing to a different database.
How can I handle this.
I’ve seen that it’s not enough to deploy the datasource xml file inside the ear, with different parameters in each ear (jdbc url/user/password) since the datasource is globally scoped and will be shared by all the ears.
Do I need to use a different datasource name for each ear and to change the persistence.xml file for each deployment? Isn’t there any other option?
I’m using JBoss 6.
Edit: Some more details
As I said the datasource is used for a JPA persistence unit, but I didn’t mention that the same datasource is used directly inside several classes that need to do direct jdbc access. So changing the name of the datasource isn’t a good option.
I think there isn’t any option to do this. JBoss AS always scopes data sources globally. There would theoretically be the
@DataSourceDefinitionordata-sourceelement in application.xml that can be app scoped.Unfortunately, this one doesn’t seem to work in JBoss AS 6 at all and even if it would work, it was stated by Jaikiran Pai that such a data source is not allowed to be used for a persistence unit anyway.
See http://community.jboss.org/thread/161032 and https://issues.jboss.org/browse/JBAS-8816
But if you’re already putting different
*-ds.xmlfiles inside each EAR, then it wouldn’t be that bad to also put a different persistence.xml inside each one, would it? At least you have the indirection that the persistence unit offers you. It would be worse if the data source name would be used directly at many places inside the EAR.It’s probably not an option, but just in case, GlassFish does allow embedded data sources to be app scoped.
If you’re interested in this feature for JBoss AS, you might want to express this here: http://community.jboss.org/message/642506