Martin
Martin

Reputation: 446

Deploy an EAR multiple times with different data-sources on the same server

Let's assume a Java EE 6 application packaged as an EAR (one EJB-JAR, N web modules and some libraries) using JPA for persistence.

The requirement is, that on one machine the applications for multiple customers need to be run. Each customer has it's own database.

The problem is now, where do you configure the data-source for each customer and how do you tell the application (on deployment or whenever) which data-source to use?

First take: replace the container-specific JNDI name in persistence.xml with something application-specific. On deployment the the application-specific name needs to be bound to a container-specific name.

The Problem: from what I read it is not possible to do the referencing withing the persistence.xml, unless you disable the enhancing of entities and thereby reducing performance, unless I completely misunderstand stood. (Source: http://lists.jboss.org/pipermail/wildfly-dev/2014-January/001541.html)

Secondly I found no way to do the resource-ref on an EAR level, I guess one has to do it in the application.xml, that is in my case generated by maven, hence I've to do it in the POM, but have no clue how, the reference of the EJB plugin is not mentioning.

But maybe I'm just on the wrong track. Any help would be appreciated.

Update - 2014-09-12: Removing auto-generation of the application.xml from POM.xml and adding <resource-ref/> to the application.xml, mapping the local JNDI name of the data-sources to the container-speicific works. (Which makes me immensely happy.)

<resource-ref>
    <res-ref-name>jdbc/customer-alpha</res-ref-name>
    <res-type>javax.sql.XADataSource</res-type>
    <lookup-name>java:jboss/datasources/customer-alpha</lookup-name>
</resource-ref>

I'm still not sure if that's really the way one would do it. And there are some other question, but they'd be asked separately, e.g. who would add the mapping to application.xml and when, what would the workflow of deploying such an application be.


-
Martin

Upvotes: 2

Views: 1227

Answers (1)

Olivier
Olivier

Reputation: 2691

I realize this question dates a bit, but just wanted to point out the property replacement feature: https://docs.jboss.org/author/display/WFLY8/Java+EE+Application+Deployment+Configuration

From what I read (didn't test it - did so for other cases though), you should be able to apply that to your persistence.xml.

So basically you could set a system property with the jndi-name to be used for a given instance of the application, and in your persistence.xml refer to the property.

Means you don't need to start touching your ear, while enabling the per customer specificity.

Upvotes: 1

Related Questions