1

I have configured a local postgres database correctly on WildFly 10.1.0. After adding my datasource on standalone.xml(and deleting the previous ExampleDS that already comes on standadole.xml) and creating my postgres folder on wildfly-10.1.0.Final/modules/system/layers/base/com/postgres/main adding module.xml and JDBC postgresql driver, I initialized it from ./standalone.sh and going to http://127.0.0.1:9990/console/App.html > Configuration > DataSources I successfully pinged my postgres database(as stated here):

Successfully created JDBC connection.
Successfully connected to database Postgres.

Now I want to configure Hibernate on my project using Intellij. The problem is I don't know to correctly set up persistence.xml to use my previously configured data source. I have the this pom.xml:

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.1.4</version>
    </dependency>

Then I have this persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
         version="2.1">

<persistence-unit name="unitName">
    <jta-data-source>java:jboss/datasources/Postgres-DS</jta-data-source>
    <class>entity.PersistentEntity.Account</class>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL82Dialect"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
</persistence-unit>

But when I upload my project on WildFly through Intellij I get this error:

17:18:06,602 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 23) HHH000228: Running hbm2ddl schema update
17:18:06,675 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 2) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "artifactId-1")]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jboss.datasources.ExampleDS"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.artifactId-1.artifactId-1.DefaultDataSource is missing [jboss.naming.context.java.jboss.datasources.ExampleDS]"]
}
17:18:06,677 ERROR [org.jboss.as.server] (management-handler-thread - 2) WFLYSRV0021: Deploy of deployment "artifactId-1.war" was rolled back with the following failure message: 
{
"WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jboss.datasources.ExampleDS"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.artifactId-1.artifactId-1.DefaultDataSource is missing [jboss.naming.context.java.jboss.datasources.ExampleDS]"]
}

The original datasource was this:

 <datasources>
            <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
                <driver>h2</driver>
                <security>
                    <user-name>sa</user-name>
                    <password>sa</password>
                </security>
            </datasource>
            <drivers>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
            </drivers>
        </datasources>

Why is it still trying to use the original datasource? Should I alter standalone-full.xml too? On standalone-full.xml there's still no postgres data source, only this h2 above.

Vsevolod Golovanov
  • 4,068
  • 3
  • 31
  • 65
rado
  • 5,720
  • 5
  • 29
  • 51

1 Answers1

2

The error concerns a default datasource:

jboss.naming.context.java.module.artifactId-1.artifactId-1.DefaultDataSource is missing [jboss.naming.context.java.jboss.datasources.ExampleDS]"] }

You deleted ExampleDS:

after ... and deleting the previous ExampleDS that already comes on standadole.xml

But the vanilla standalone.xml that comes with Wildfly 10.1.0.Final references the ExampleDS datasource as a default datasource:

<subsystem xmlns="urn:jboss:domain:ee:4.0">
    <default-bindings
        ...
        datasource="java:jboss/datasources/ExampleDS"
        ...

You probably didn't fix this.

Your persistence.xml datasource reference seems fine (you didn't post your datasource definition in the standalone.xml though).

Vsevolod Golovanov
  • 4,068
  • 3
  • 31
  • 65
  • I reverted ExampleDS and it worked. Thanks for your answer. Do you know where can I find details about which data source configurations should be on `standalone.xml` and which should be on `persistence.xml`? – rado Sep 17 '17 at 18:35
  • 1
    @GabrielRado, Wildfly's distribution includes schemas, the datasources one is at the `wildfly-10.1.0.Final/docs/schema/wildfly-datasources_4_0.xsd`. Also there is this: https://docs.jboss.org/author/display/WFLY10/DataSource+configuration . As to persistence.xml, see JPA spec, Hibernate docs, http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd ... – Vsevolod Golovanov Sep 17 '17 at 19:39
  • I don't get it, what do you mean when you say `You deleted ExampleDS after ... and deleting the previous ..` I don't have a standalone.xml and I have the same error, any idea ? – Rom May 26 '19 at 20:42
  • @RomainB., the error means that something references a non-existent datasource. If that doesn't clear up your problem, I recommend creating a new question and describing in it what you're doing in detail: which server version you're using, how are you configuring it etc. Otherwise it's hard to guess the issue. – Vsevolod Golovanov May 30 '19 at 12:05