4 Replies Latest reply on Apr 15, 2019 10:53 PM by akaine

    Wildfly 16, PostgreSQL datasource not working

    akaine

      Hello,

       

      I've been trying to migrate my existing web application from Wildfly 10 to Wildfly 16 when I encountered a weird problem.

       

      Just to explain what I did to configure the DS and the things involved:

      1. Set EclipseLink 2.7.3 as default persistence provider (did it already many times with different Jboss/Wildfly versions without any issues and have several production servers running with it). The process is described here pretty thoroughly: JPA Reference Guide - WildFly 10 - Project Documentation Editor

      2. Installed PostgreSQL driver JAR module using CLI:

      module add --name=org.postgres --resources=postgresql-42.2.5.jar --dependencies=javax.api,javax.transaction.api

      3. Using Web console added a "PostgreSQL" driver pointing to the installed module.

      4. Using Web console added a datasource called "testDS". Preliminary testing reported no errors and the server starts without any problems.

       

      However, I noticed the following message during the server start:

      20:08:56,072 WARN  [org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService$AS7DataSourceDeployer] (MSC service thread 1-3) IJ020020: 
      Connection Properties for DataSource: 'java:/testDS' is empty, 
      try to use driver-class: 'org.postgresql.Driver' 
      and connection-url: 'jdbc:postgresql://localhost:5432/testdb' to connect database

       

      Now when I actually try to connect to my database and run a JPA query I see the following:

      20:45:42,149 INFO  [org.eclipse.persistence] (default task-1) EclipseLink, version: Eclipse Persistence Services - 2.7.3.v20180807-4be1041
      20:45:42,240 INFO  [org.eclipse.persistence.connection] (default task-1) connecting(DatabaseLogin(
          platform=>PostgreSQLPlatform
          user name=> ""
          connector=>JNDIConnector datasource name=>null
      ))
      20:45:42,240 INFO  [org.eclipse.persistence.connection] (default task-1) Connected: jdbc:postgresql://localhost/
          User: postgres
          Database: PostgreSQL  Version: 10.6
          Driver: PostgreSQL JDBC Driver  Version: 42.2.5
      20:45:42,240 INFO  [org.eclipse.persistence.connection] (default task-1) connecting(DatabaseLogin(
          platform=>PostgreSQLPlatform
          user name=> ""
          connector=>JNDIConnector datasource name=>null
      ))
      20:45:42,240 INFO  [org.eclipse.persistence.connection] (default task-1) Connected: jdbc:postgresql://localhost/
          User: postgres
          Database: PostgreSQL  Version: 10.6
          Driver: PostgreSQL JDBC Driver  Version: 42.2.5
      20:45:42,256 WARN  [org.eclipse.persistence.metadata] (default task-1) Reverting the lazy setting on the OneToOne or ManyToOne attribute [profile] for the entity class [class com.akaine.test.eb.Employee] since weaving was not enabled or did not occur.
      20:45:42,272 INFO  [org.eclipse.persistence.connection] (default task-1) /vfs:/E:/_CODE/_SERVER/wildfly-16.0.0.Final-EM/standalone/deployments/wildfly-test.war/WEB-INF/classes/_testPU login successful
      20:45:42,365 INFO  [org.eclipse.persistence.query] (default task-1) Communication failure detected when attempting to perform read query outside of a transaction. Attempting to retry query. Error was: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
      Internal Exception: org.postgresql.util.PSQLException: ERROR: relation "employee" does not exist
      

       

      Notice the truncated connection URL after the host. After this, obviously, the rest goes bonkers, since, as I understand, the datasource does not even provide a proper connection to my database.

       

      For the reference, I'm attaching my installed-drivers-list and datasources:read-resource(recursive=true) CLI outputs.

       

      So any idea what may cause this? I've noticed some considerable differences between Wildfly v15 and v16, though the v16 manual says nothing out of the ordinary regarding the datasource creation.

        • 1. Re: Wildfly 16, PostgreSQL datasource not working
          mayerw01

          How does ypur persistence.xml look like?

          • 2. Re: Wildfly 16, PostgreSQL datasource not working
            rcd

            You're defining datasource-class in your driver. That means you're required to use connection-properties, because connection-url will be ignored. See WFLY-6157 and WFLY-6200.

            • 3. Re: Wildfly 16, PostgreSQL datasource not working
              akaine

              , my persistence.xml looks like this:

              <?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://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
                  <persistence-unit name="testPU" transaction-type="JTA">
                      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
                        <jta-data-source>java:/testDS</jta-data-source>
                      <properties>
                            <property name="eclipselink.jdbc.uppercase-columns" value="true"/>
                            <property name="eclipselink.jdbc.fetch-size" value="256"/>
                            <property name="eclipselink.jdbc.batch-writing" value="jdbc"/>
                            <property name="eclipselink.weaving" value="false" />
                      </properties>
                  </persistence-unit>
              </persistence>
              

               

              , yeah, I remember seeing those two while I was searching for the answer to my problem. Though at no moment these two tickets explain where and how to set these connection-properties. Could you point me in the right direction please?

              • 4. Re: Wildfly 16, PostgreSQL datasource not working
                akaine

                Ok found it. Adding the following line worked:

                <connection-property name="url">jdbc:postgresql://localhost:5432/testdb</connection-property>

                 

                Now my standalone.xml looks like this:

                <datasource jta="true" jndi-name="java:/testDS" pool-name="testDS">
                    <connection-property name="url">jdbc:postgresql://localhost:5432/testdb</connection-property>
                    <connection-url>jdbc:postgresql://localhost:5432/testdb</connection-url>
                    <driver-class>org.postgresql.Driver</driver-class>
                    <datasource-class>org.postgresql.ds.PGSimpleDataSource</datasource-class>
                    <driver>PostgreSQL</driver>
                    <security>
                        <user-name>postgres</user-name>
                        <password>postgres</password>
                    </security>
                    <validation>
                        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
                        <background-validation>true</background-validation>
                        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
                    </validation>
                </datasource>
                

                 

                Thanks!