2

My question is: How do I map a datasource to a specific jndi-name configured inside wildfly so that multiple deployed .war-files each can use their own specific datasource. The mapping should take place at deployment so that a configuration inside wildfly and the specific project is sufficient.

We got a project which supports multi-tenancy. The structure is as follows:

customerSpecificProject
|-- ui (generic)
  |----database (generic)
  |----services (generic)
  |----etc...

In the database-project a standard datasource is specified which goes by a standard jndi-name java:/xyzDS. Since we migrated from tomcat to wildfly we want to make use of the ability to host multiple applications in our AS.

To achieve this we have to map the java:/xyzDS to the datasources defined in the standalone.xml:

<subsystem xmlns="urn:jboss:domain:datasources:4.0">
        <datasources>
            <datasource jta="true" jndi-name="java:/customer1DS" pool-name="c1DS" enabled="true" use-ccm="true">
               ...
            </datasource>
            <datasource jta="true" jndi-name="java:/customer2DS" pool-name="c2DS" enabled="true" use-ccm="true">
                ...
            </datasource>

Therefore we tried to use the jboss-web.xml located in the WEB-INF folder of our customerProject:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
  http://www.jboss.com/xml/ns/javaee
  http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
  <resource-ref>
    <res-ref-name>java:/xyzDS</res-ref-name>
    <jndi-name>java:/customer1DS</jndi-name>
  </resource-ref>
</jboss-web>

persistence.xml inside the database-Project:

<?xml version='1.0' encoding='UTF-8'?>
<persistence version="2.1"
  xmlns="http://xmlns.jcp.org/xml/ns/persistence" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence                              
  http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="xyzDB" transaction-type="JTA">
    <jta-data-source>java:/xyzDS</jta-data-source>
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>...</class>
    ...
    <class>...</class>
    <shared-cache-mode>NONE</shared-cache-mode>
    <validation-mode>NONE</validation-mode>
    <properties>
        <property name="eclipselink.weaving" value="static" />
    </properties>
  </persistence-unit>
</persistence>

It does not seem to be working. I talked to a colleague who had a similar issue and resolved it in the corresponding way for a websphere AS. I do not know if the problem resides in the structure having a nested databaseProject inside another lib (ui) for the actual customerProject or if it is caused by bad configuration.

Also we use the @Resource Annotation inside some DAOs:

@Resource(lookup = "java:/xyzDS")
private DataSource dataSource;

Maybe the mapping works but not for the annotations inside the compiled DAOs? But I do not understand why that should not work.

Current Error in Stacktrace:

11:18:20,839 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: { "WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"xyz.war\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"xyz.war\".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment \"xyz.war\" Caused by: java.lang.IllegalArgumentException: WFLYEE0047: Incompatible conflicting binding at java:/xyzDS source: lookup (java:/customer1DS)"},

Edit: Already tried adding:

<property name="wildfly.jpa.twophasebootstrap" value="false"/>

To persistence.xml

1 Answers1

0

Have you checked the question/answer in wildfly-development.1055759.n5.nabble.com? In this exchange, it was determined that the persistence unit needed a hint in the form of

<property name="wildfly.jpa.twophasebootstrap" value="false"/>

I don't know if this is applicable in your case, but is worth looking at.

  • Sadly I already tried to add that property (forgot to mention it - sorry) and it did not resolve to issue. Thank you anyway. – KhaosTheory Mar 17 '18 at 09:18