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.