Problems creating Wildfly 10 datasource - postgresql

I am trying to create a datasource in Wildfly 10 to connect with a PostgreSQL 9.5 database, I already saw some tutorials in Internet and still I can't do it.
If someone can help me I will be very thankfull.
This is the error message :enter code here
9:06:46,300 ERROR [org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService$AS7DataSourceDeployer] (MSC service thread 1-6) Error during the deployment of java:jboss/datasources/CiberWebCopierDS: javax.resource.ResourceException: IJ031103: At least one connection property must be defined for datasource-class: org.postgresql.Driver
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createConnectionFactory(LocalManagedConnectionFactory.java:108)
at org.jboss.jca.deployers.common.AbstractDsDeployer.deployDataSource(AbstractDsDeployer.java:772)
at org.jboss.jca.deployers.common.AbstractDsDeployer.createObjectsAndInjectValue(AbstractDsDeployer.java:312)
at org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService$AS7DataSourceDeployer.deploy(AbstractDataSourceService.java:371)
at org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService.start(AbstractDataSourceService.java:149)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
19:06:46,305 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC000001: Failed to start service org.wildfly.data-source.CiberWebCopierDS: org.jboss.msc.service.StartException in service org.wildfly.data-source.CiberWebCopierDS: WFLYJCA0033: Error during the deployment of CiberWebCopierDS
at org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService.start(AbstractDataSourceService.java:163)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.jboss.msc.service.StartException in anonymous service: WFLYJCA0032: Unable to start the ds because it generated more than one cf
at org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService.start(AbstractDataSourceService.java:151)
... 5 more
and this
19:06:47,988 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "CiberWebCopierDS")
]) - failure description: {
"WFLYCTL0080: Failed services" => {"org.wildfly.data-source.CiberWebCopierDS" => "org.jboss.msc.service.StartException in service org.wildfly.data-source.CiberWebCopierDS: WFLYJCA0033: Error during the deployment of CiberWebCopierDS
Caused by: org.jboss.msc.service.StartException in anonymous service: WFLYJCA0032: Unable to start the ds because it generated more than one cf"},
"WFLYCTL0412: Required services that are not installed:" => ["org.wildfly.data-source.CiberWebCopierDS"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined
}
19:06:47,990 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "CiberWebCopierDS")
]) - failure description: {
"WFLYCTL0080: Failed services" => {"org.wildfly.data-source.CiberWebCopierDS" => "org.jboss.msc.service.StartException in service org.wildfly.data-source.CiberWebCopierDS: WFLYJCA0033: Error during the deployment of CiberWebCopierDS
Caused by: org.jboss.msc.service.StartException in anonymous service: WFLYJCA0032: Unable to start the ds because it generated more than one cf"},
"WFLYCTL0412: Required services that are not installed:" => [
"org.wildfly.data-source.CiberWebCopierDS",
"org.wildfly.data-source.CiberWebCopierDS"
],
"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined
}
19:06:48,017 INFO [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186: Services which failed to start: service org.wildfly.data-source.CiberWebCopierDS: org.jboss.msc.service.StartException in service org.wildfly.data-source.CiberWebCopierDS: WFLYJCA0033: Error during the deployment of CiberWebCopierDS.
This is how I create the module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.h2database.h2">
<resources>
<resource-root path="h2-1.3.173.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
this is the driver definition:
<driver name="postgres" module="org.postgresql">
<datasource-class>org.postgresql.Driver</datasource-class>
</driver>
and this is the datasource definition:
<datasource jndi-name="java:jboss/datasources/CiberWebCopierDS" enabled="true" use-java-context="true" pool-name="CiberWebCopierDS">
<connection-rl>jdbc:postgresql://localhost:5432/CiberWebCopierDB</connection- url>
<driver>postgres</driver>
<security>
<user-name>postgres</user-name>
<password>postgresql</password>
</security>
</datasource
>

The module.xml you provided is not for postgres, it's for a h2 database..
Try using the following module, and remember to download postrgres driver, place it in modules/org/postgresql/main and change "postgresql-Y.X-Z.jdbcV.jar" to the name of the driver you downloaded.
The rest of your config looks good, but I'm not so sure about setting datasource-class in the driver section, I think that goes in the datasource declaration, using driver-class element.
To sum up:
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.postgresql">
<resources>
<resource-root path="postgresql-Y.X-Z.jdbcV.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
driver definition
<driver name="postgres" module="org.postgresql"/>
datasource definition
<datasource jndi-name="java:jboss/datasources/CiberWebCopierDS" enabled="true" use-java-context="true" pool-name="CiberWebCopierDS">
<connection-url>jdbc:postgresql://localhost:5432/CiberWebCopierDB</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgres</driver>
<security>
<user-name>postgres</user-name>
<password>postgresql</password>
</security>
</datasource>
EDIT: As a side note, I think that if you want to declare the datasource class in the driver section, you need to use xa-datasource-class element instead of datasource-class, you can try it if you want.

Related

PostgreSQL 13 + Hibernate 6.0.2 + wildfly-preview-27.0.0.Alpha5 Error

I have to configure my PostgreSQL datasource for WildFly in order to use it in my Jakarta EE 10 with hibernate 6.0.2
Below shown are my configuration
Postgresql module in widfly
<?xml version="1.0" ?>
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
Datasource
<datasource jndi-name="java:jboss/datasources/nextu" pool-name="nextu">
<connection-url>jdbc:postgresql://localhost:5432/nextu</connection-url>
<driver>postgres</driver>
<security>
<user-name>nextu</user-name>
<password>nextu</password>
</security>
</datasource>
Driver used
org.postgresql.Driver
Persistence.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence
xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_1.xsd"
version="3.1">
<persistence-unit name="primary">
<jta-data-source>java:jboss/datasources/nextu</jta-data-source>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<!-- AUTO-GENERATES DATABASE FROM ANNOTATIONS METADATA -->
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="javax.persistence.schema-generation.create-source" value="metadata"/>
<property name="javax.persistence.schema-generation.drop-source" value="metadata"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/>
</properties>
</persistence-unit>
</persistence>
Error I am getting while running:
00:50:49,304 ERROR [org.jboss.msc.service.fail] (ServerService
Thread Pool -- 80) MSC000001: Failed to start service
jboss.persistenceunit."servlet-0.0.1-SNAPSHOT.war#primary":
org.jboss.msc.service.StartException in service
jboss.persistenceunit."servlet-0.0.1-SNAPSHOT.war#primary":
java.lang.ExceptionInInitializerError at
org.jboss.as.jpa#27.0.0.Alpha5//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:199)
at
org.jboss.as.jpa#27.0.0.Alpha5//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:129)
at
java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at
org.wildfly.security.elytron-base#2.0.0.Beta3//org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:664)
at
org.jboss.as.jpa#27.0.0.Alpha5//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:214)
at
org.jboss.threads#2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at
org.jboss.threads#2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at
org.jboss.threads#2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at
org.jboss.threads#2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.base/java.lang.Thread.run(Thread.java:833) at
org.jboss.threads#2.4.0.Final//org.jboss.threads.JBossThread.run(JBossThread.java:513)
Caused by: java.lang.ExceptionInInitializerError at
org.hibernate#6.0.2.Final//org.hibernate.dialect.PostgreSQLDialect.contributeTypes(PostgreSQLDialect.java:1107)
at
org.hibernate#6.0.2.Final//org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:374)
at
org.hibernate#6.0.2.Final//org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:144)
at
org.hibernate#6.0.2.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1350)
at
org.hibernate#6.0.2.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1421)
at
org.hibernate.jipijapa-hibernate6#27.0.0.Alpha5//org.jboss.as.jpa.hibernate.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:45)
at
org.jboss.as.jpa#27.0.0.Alpha5//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:171)
... 10 more Caused by: java.lang.RuntimeException: Could not
initialize PostgreSQLPGObjectJdbcType at
org.hibernate#6.0.2.Final//org.hibernate.dialect.PostgreSQLIntervalSecondJdbcType.<clinit>(PostgreSQLIntervalSecondJdbcType.java:78)
... 17 more Caused by: java.lang.NoSuchMethodException:
org.postgresql.util.PGInterval.getWholeSeconds() at
java.base/java.lang.Class.getDeclaredMethod(Class.java:2675) at
org.hibernate#6.0.2.Final//org.hibernate.dialect.PostgreSQLIntervalSecondJdbcType.<clinit>(PostgreSQLIntervalSecondJdbcType.java:74)
... 17 more
00:50:49,307 ERROR [org.jboss.as.controller.management-operation]
(Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed -
address: ([("deployment" => "servlet-0.0.1-SNAPSHOT.war")]) -
failure description: {"WFLYCTL0080: Failed services" =>
{"jboss.persistenceunit."servlet-0.0.1-SNAPSHOT.war#primary"" =>
"java.lang.ExceptionInInitializerError Caused by:
java.lang.ExceptionInInitializerError Caused by:
java.lang.RuntimeException: Could not initialize
PostgreSQLPGObjectJdbcType Caused by: java.lang.NoSuchMethodException:
org.postgresql.util.PGInterval.getWholeSeconds()"}} 00:50:49,360 INFO
[org.jboss.as.server] (ServerService Thread Pool -- 46) WFLYSRV0010:
Deployed "servlet-0.0.1-SNAPSHOT.war" (runtime-name :
"servlet-0.0.1-SNAPSHOT.war") 00:50:49,361 INFO
[org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183:
Service status report WFLYCTL0186: Services which failed to start:
service jboss.persistenceunit."servlet-0.0.1-SNAPSHOT.war#primary":
java.lang.ExceptionInInitializerError WFLYCTL0448: 11 additional
services are down due to their dependencies being missing or failed
00:50:49,408 INFO [org.jboss.as.server] (Controller Boot Thread)
WFLYSRV0212: Resuming server 00:50:49,410 ERROR [org.jboss.as]
(Controller Boot Thread) WFLYSRV0026: WildFly Preview 27.0.0.Alpha5
(WildFly Core 19.0.0.Beta15) started (with errors) in 9738ms - Started
412 of 658 services (13 services failed or missing dependencies, 362
services are lazy, passive or on-demand) - Server configuration file
in use: standalone.xml
I found the solution, I had PostgreSQL dependencies in my pom maven.This is the code added.
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifestEntries>
<Dependencies>org.postgres</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
NB : org.postgres => the name of my module Postgres previously define in widfly.

Configure HSQLDB datasource with Thorntail / Wildfly Swarm

I have a problem with thorntail / wildfly.
I am trying to declare hsql driver and i don't success.
Thorntail says me:
2022-08-24 15:48:08,912 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 35) WFLYCTL0013: L'op�ration ("add") a �chou� - adresse : ([
("subsystem" => "datasources"),
("jdbc-driver" => "org.hsqldb")
I guess I put wrong values in datasources / jdbc-drivers.
But what are the right values ?
Here's the extract of configuration:
swarm:
logging: INFO
http:
port: 8080
datasources:
jdbc-drivers:
org.hsqldb:
driver-class-name: org.hsqldb.jdbc.JDBCDriver
xa-datasource-class-name: org.hsqldb.jdbc.pool.JDBCXADataSource
driver-module-name: org.hsqdb
Thanks,
Stéphne
I found the solution...
Th proble mwas that i had a diffrence between the file module.xml and the driver-module-name attribute like this: one character was missing.
module.xml
<?xml version='1.0' encoding='UTF-8'?>
<module xmlns="urn:jboss:module:1.1" name="org.hsqldb">
<resources>
<resource-root path="hsqldb-2.7.0.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
And :
swarm:
logging: INFO
http:
port: 8080
datasources:
jdbc-drivers:
org.hsqldb:
driver-class-name: org.hsqldb.jdbcDriver
xa-datasource-class-name: org.hsqldb.jdbc.pool.JDBCXADataSource
driver-module-name: org.hsqdb
That was all.... ;-)
Stéphane

Oracle DB Connection: failure description: "WFLYJCA0041: Failed to load module for driver [com.oracle]

Setting up connection to Oracle19C from Keycloak 12.0.3
Receiving message: "failure description: "WFLYJCA0041: Failed to load module for driver [com.oracle]"
I've relooked x100 and can't seem to find what is missing. Could any kind soul review the below for what I have missed?
JAR File path:
/modules/system/layers/keycloak/com/oracle/main
module.xml
ojdbc10.jar
standalone.xml
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
<connection-url>jdbc:oracle:thin:#DBURL:1521:SID</connection-url>
<driver>oracle</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
<flush-strategy>IdleConnections</flush-strategy>
</pool>
<security>
<user-name>USER</user-name>
<password>PASSWORD</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/>
<check-valid-connection-sql>select 1 from dual</check-valid-connection-sql>
<background-validation>true</background-validation>
<stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker"/>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter"/>
</validation>
<timeout>
<blocking-timeout-millis>5000</blocking-timeout-millis>
<idle-timeout-minutes>5</idle-timeout-minutes>
</timeout>
</datasource>
<driver name="oracle" module="com.oracle">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
module.xml
<?xml version=”1.0" ?><?xml version='1.0' encoding='UTF-8'?>
<module xmlns=”urn:jboss:module:1.3" name=”com.oracle”>
<resources>
<resource-root path=”ojdbc10.jar”/>
</resources>
<dependencies>
<module name=”javax.api”/>
<module name=”javax.transaction.api”/>
</dependencies>
</module>
I had this issue, and the only way I could solve it was to place the oracle driver in the keycloak/modules directory.
These did not work:
keycloak/modules/system/layers/keycloak/com/oracle It is here that is described in the KeyCloak documentation, and it worked for me for Postgres, but I could not get the oracle driver to load from here.
keycloak/modules/system/layers/base/com/oracle : Tried this out of desperation.
But this worked for me in:
keycloak/modules/com/oracle
keycloak/modules/com/oracle/main/module.xml
<?xml version='1.0' encoding='UTF-8'?>
<module xmlns="urn:jboss:module:1.1" name="com.oracle">
<resources>
<resource-root path="ojdbc8.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
And the ojdbc8.jar file was also in this directory.
NOTE: The name="com.oracle" has to match the path com/oracle in the module directory.
In the standalone.xml file, I added the following datasource.
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
<connection-url>jdbc:oracle:thin:#hostname:1521:SID</connection-url>
<driver>oraclejdbc</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>20</max-pool-size>
</pool>
<security>
<user-name>user</user-name>
<password>password</password>
</security>
</datasource>
With the matching driver
<driver name="oraclejdbc" module="com.oracle">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
NOTE:
the module="com.oracle" matches the path com/oracle.
the driver name="oraclejdbc" matches the <driver>oraclejdbc</driver> element.
Once working, I saws this in the log.
2021-05-31 14:46:17,376 INFO [org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory] (ServerService Thread Pool -- 60) Database info: {databaseUrl=jdbc:oracle:thin:#server:1521:SID, databaseUser=user, databaseProduct=Oracle Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.10.0.0.0, databaseDriver=Oracle JDBC driver 19.3.0.0.0}
But prior to it working I would see the following errors in the log (which I am including, incase people are googling the error message)
2021-05-31 14:47:12,049 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 50) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "oraclejdbc")
]) - failure description: "WFLYJCA0115: Module for driver [com.oracle] or one of it dependencies is missing: [com.oracle]"
Or this error
2021-05-31 14:47:14,962 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "KeycloakDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.oraclejdbc"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"org.wildfly.data-source.KeycloakDS is missing [jboss.jdbc-driver.oraclejdbc]",
"jboss.driver-demander.java:jboss/datasources/KeycloakDS is missing [jboss.jdbc-driver.oraclejdbc]"
]
}
Adde module via commandline.
module add --name=oracle.jdbc --resources=customization/ojdbc10.jar --dependencies=javax.transaction.api
Created under the following structure:
-keycloak
--modules
----oracle
------jdbc
--------main
----------module.xml
----------ojdbc10.jar

wildfly wont start because of new missing/unsatisfied dependencies

When I try to start my WildFly server, I got this error :
2018-11-17 21:29:55,203 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "org.postgresql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [org.postgresql]"
ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "swap")
]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.driver-demander.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]",
"jboss.data-source.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]"
]}
2018-11-17 21:30:07,625 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "swap")
]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.driver-demander.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]",
"jboss.data-source.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]",
"jboss.data-source.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]"
]}
And my standalone.xml :
<datasources>
<datasource jndi-name="java:jboss/datasources/swap" pool-name="swap" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://127.0.0.1:5432/swap?useUnicode=yes&characterEncoding=UTF-8</connection-url>
<driver>org.postgresql</driver>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
</datasource>
<drivers>
<driver name="org.postgresql" module="org.postgresql">
<driver-class>org.postgresql.Driver</driver-class>
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
</drivers>
</datasources>
My PostgreSQL module.xml :
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
</resources>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
What could be the problem? Please help and Thanks.
Your module.xml is invalid. A <dependencies> tag is missing. Try it with the following:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
EDIT:
The module.xml file and the postgresql-42.2.5.jar have to be in
C:\wildfly\wildfly-9.0.2.Final\modules\system\layers\base\org\postgresql\main.
It is also recommended to put your modules directly into
C:\wildfly\wildfly-9.0.2.Final\modules\.
So in your case C:\wildfly\wildfly-9.0.2.Final\modules\org\postgresql\main, that can be problem.
For reference, also have a look at the EAP7 Documentation and you should also think about using the jboss-cli.
For configuration of PostgresSQL for WildFly server, you should follow the following steps.
Step 1 : Adding PostgreSQL Module
Create new folder ${wildfly_home}/modules/system/layers/base/org/postgresql/main/ if not exist.
Download Latest Driver Jar via this link => https://jdbc.postgresql.org/download.html and put under the above folder.
Also in that new folder, Create module.xml and put the following config.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.23.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
May be jar version need to update in resource-root.
Step 2 : Update DB configs from standalone.xml
Remove Existing <driver> config and add new config as follow.
<driver name="postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
Remove existing <datasource> config and add new config as follow.
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://127.0.0.1:5432/swap?useUnicode=yes&characterEncoding=UTF-8</connection-url>
<driver>postgresql</driver>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
<pool>
<max-pool-size>20</max-pool-size>
</pool>
</datasource>
Modify default-bindings datasource name to PostgresDS from ExampleDS.
<default-bindings context-service="java:jboss/ee/concurrency/context/default" datasource="java:jboss/datasources/PostgresDS" ...
Make sure that you have created your swap database in PostgreSQL database server.
Now, run server and it will be fine.

Use H2-mem as persistence unit

i'm new in the world of java-ee. I try to implement an java-ee App. I'm having some trouble to configure the persistence.xml. I want the default java h2:mem to be my persistence unit. Hier is my persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/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_1_0.xsd"
version="1.0">
<persistence-unit name="customerDatabase">
<description>My Customer-DB</description>
</persistence-unit>
<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</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>
</persistence>
It's something wrong with it because i'm getting the error:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'datasource'. One of '{"http://java.sun.com/xml/ns/persistence":persistence-unit}'
is expected.
what does the persistence.xml miss?
I changed my provider and i'm now using hibernate... Now i'm getting errors from an other order. Can anybody helps?
11:21:46,092 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 59) MSC000001: Failed to start service jboss.persistenceunit."javaee7-master.war#customerDatabase": org.jboss.msc.service.StartException in service jboss.persistenceunit."javaee7-master.war#customerDatabase": javax.persistence.PersistenceException: [PersistenceUnit: customerDatabase] Unable to build Hibernate SessionFactory
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:665)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: customerDatabase] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)
... 7 more
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: de.ostfalia.entity.Customer
at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:277)
at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:224)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:775)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
... 12 more
11:21:46,098 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "javaee7-master.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"javaee7-master.war#customerDatabase\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"javaee7-master.war#customerDatabase\": javax.persistence.PersistenceException: [PersistenceUnit: customerDatabase] Unable to build Hibernate SessionFactory
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: customerDatabase] Unable to build Hibernate SessionFactory
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: de.ostfalia.entity.Customer"}}
11:21:46,197 INFO [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "postgresql-9.4-1203.jdbc42.jar" (runtime-name : "postgresql-9.4-1203.jdbc42.jar")
11:21:46,198 INFO [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "javaee7-master.war" (runtime-name : "javaee7-master.war")
11:21:46,200 INFO [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186: Services which failed to start: service jboss.persistenceunit."javaee7-master.war#customerDatabase": org.jboss.msc.service.StartException in service jboss.persistenceunit."javaee7-master.war#customerDatabase": javax.persistence.PersistenceException: [PersistenceUnit: customerDatabase] Unable to build Hibernate SessionFactory
According to the official schema, the <persistence> element can only contain persistence-unit elements. I would suggest you start with upgrading from JPA 1.0 to 2.0 (requires Java 6) or 2.1 (requires Java 7). An example persistence.xml 2.1 would be as follows:
<?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="customerDatabase" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value="sa"/>
</properties>
</persistence-unit>
</persistence>
This configuration presumes your application gets the java:jboss/datasources/ExampleDS data source from some other configuration, like for example in Apache Tomcat, it would be in the context.xml and the properties listed in this example would not be necessary.
The provider is different if you're not using the EclipseLink library.
Also non-jta-data-source might have to be jta-data-source in your case.
update:
The error you are getting now comes from No identifier specified for entity: de.ostfalia.entity.Customer. You need to make sure all your entity classes have properly specified Id columns. If you are using JPA annotations, that would be the #Id annotation. You may also need a #GeneratedValue on it, if the database automatically assigns the ID on insert for that table (the most common case). There is also the option of specifying them through a mapping.xml file. These tutorials will get you started with good examples http://www.tutorialspoint.com/jpa/jpa_orm_components.htm http://www.javaworld.com/article/2077817/java-se/understanding-jpa-part-1-the-object-oriented-paradigm-of-data-persistence.html
One thing I learned the hard way is that every time you do EntityManager em = entityManagerFactory.createEntityManager(); you must em.close() it in the end, no matter if you've committed or rolled-back the transaction, which means you must also catch any Throwables that may occur. In our webapp, we do this by using a javax.servlet.Filter (only applies to webapps) for all urls. If you leave it open for too long with no activity, the database will eventually drop the connection (which might not happen in H2 specifically) and the thread becomes unusable until you restart the server.