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

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.

Related

wildfly-preview-25.0.0.Final - Jakarta 'org.hibernate.ogm.jpa.HibernateOgmPersistence' not found

Trying to move my (working) PoC from WildFly 25.0.0.Final - Jakarta EE 8 Full to:
WildFly 25.0.0.Final - Preview EE 9.1 Distribution
Using HibernatePersistenceProvider with MySQL & MongoDB:
<?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_2_0.xsd"
version="2.0">
<persistence-unit name="nOTiFYwellMySQLPersistenceUnit" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/NOTiFYwellDS</jta-data-source>
<class>com.notifywell.entity.FoodsCosmeticsMedicines</class>
<class>com.notifywell.entity.Ingredients</class>
<properties>
<!-- <property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2"/> -->
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.3"/>
<property name="hibernate.connection.url" value="jdbc:mysql://127.0.0.1:3306/notifywell"/>
<property name="hibernate.connection.driver_class" value="com.mysql.cj.jdbc.Driver"/>
<property name="hibernate.connection.release_mode" value="auto"/>
<property name="hibernate.connection.username" value="NOTiFY"/>
<property name="hibernate.connection.password" value="Biggles-1957"/>
<property name="wildfly.jpa.twophasebootstrap" value="false" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
<persistence-unit name="nOTiFYwellMongoDBPersistenceUnit" transaction-type="JTA">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<properties>
<!-- <property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2"/> -->
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.3"/>
<!-- <property name="wildfly.jpa.hibernate.search.module" value="org.hibernate.search.orm:5.8"/> -->
<property name="wildfly.jpa.hibernate.search.module" value="org.hibernate.search.orm:5.10"/>
<!-- <property name="hibernate.transaction.jta.platform" value="JBossTS"/> -->
<!-- <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAS"/> -->
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/>
<property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
<property name="hibernate.ogm.datastore.grid_dialect" value="org.hibernate.ogm.datastore.mongodb.MongoDBDialect"/>
<property name="hibernate.ogm.datastore.database" value="notifyWellDB"/>
<!-- <property name="hibernate.ogm.mongodb.host" value="127.0.0.1"/> -->
<!-- <property name="hibernate.ogm.datastore.host" value="172.17.0.2:27017"/> -->
<property name="hibernate.ogm.datastore.host" value="127.0.0.1:27017"/>
</properties>
</persistence-unit>
</persistence>
I've added to Gradle:
implementation group: 'org.hibernate', name: 'hibernate-search-orm', version: '5.11.9.Final'
Get:
09:40:13,191 INFO [org.jboss.as.jpa] (MSC service thread 1-8) WFLYJPA0002: Read persistence.xml for nOTiFYwellMySQLPersistenceUnit
09:40:13,192 INFO [org.jboss.as.jpa] (MSC service thread 1-8) WFLYJPA0002: Read persistence.xml for nOTiFYwellMongoDBPersistenceUnit
Caused by:
Caused by: jakarta.persistence.PersistenceException: WFLYJPA0057: PersistenceProvider 'org.hibernate.ogm.jpa.HibernateOgmPersistence' not found
List of error:
09:40:13,668 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."NOTiFYwell.ear".FIRST_MODULE_USE: org.jboss.msc.service.StartException in service jboss.deployment.unit."NOTiFYwell.ear".FIRST_MODULE_USE: WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment "NOTiFYwell.ear"
at org.jboss.as.server#17.0.1.Final//org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:189)
at org.jboss.msc#1.4.13.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
at org.jboss.msc#1.4.13.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
at org.jboss.msc#1.4.13.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
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)
Caused by: jakarta.persistence.PersistenceException: WFLYJPA0057: PersistenceProvider 'org.hibernate.ogm.jpa.HibernateOgmPersistence' not found
at org.jboss.as.jpa#25.0.0.Final//org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.lookupProvider(PersistenceUnitServiceHandler.java:1001)
at org.jboss.as.jpa#25.0.0.Final//org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.nextPhaseDependsOnPersistenceUnit(PersistenceUnitServiceHandler.java:1044)
at org.jboss.as.jpa#25.0.0.Final//org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.deploy(PersistenceUnitServiceHandler.java:139)
at org.jboss.as.jpa#25.0.0.Final//org.jboss.as.jpa.processor.PersistenceBeginInstallProcessor.deploy(PersistenceBeginInstallProcessor.java:52)
at org.jboss.as.server#17.0.1.Final//org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:182)
... 8 more
09:40:13,671 ERROR [org.jboss.as.controller.management-operation] (External Management Request Threads -- 1) WFLYCTL0013: Operation ("add") failed - address: ([("deployment" => "NOTiFYwell.ear")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"NOTiFYwell.ear\".FIRST_MODULE_USE" => "WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment \"NOTiFYwell.ear\"
Caused by: jakarta.persistence.PersistenceException: WFLYJPA0057: PersistenceProvider 'org.hibernate.ogm.jpa.HibernateOgmPersistence' not found"}}
09:40:13,672 ERROR [org.jboss.as.controller.management-operation] (External Management Request Threads -- 1) WFLYCTL0013: Operation ("add") failed - address: ([("deployment" => "NOTiFYwell.ear")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"NOTiFYwell.ear\".FIRST_MODULE_USE" => "WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment \"NOTiFYwell.ear\"
Caused by: jakarta.persistence.PersistenceException: WFLYJPA0057: PersistenceProvider 'org.hibernate.ogm.jpa.HibernateOgmPersistence' not found"}}
09:40:13,673 ERROR [org.jboss.as.server] (External Management Request Threads -- 1) WFLYSRV0021: Deploy of deployment "NOTiFYwell.ear" was rolled back with the following failure message:
{"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"NOTiFYwell.ear\".FIRST_MODULE_USE" => "WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment \"NOTiFYwell.ear\"
Caused by: jakarta.persistence.PersistenceException: WFLYJPA0057: PersistenceProvider 'org.hibernate.ogm.jpa.HibernateOgmPersistence' not found"}}
2
Have upgraded to the new Namespace:
import javax.ejb.*;
import javax.persistence.*;
to:
import jakarta.ejb.*;
import jakarta.persistence.*;
I need to upgrade WildFly 25.0.0.Final 'module' on:
org/hibernate/ogm/5.4/
org/hibernate/ogm/internal
org/hibernate/ogm/jipijapa
org/hibernate/ogm/main
org/hibernate/ogm/mongodb
etc. 'main' to:
Jakarta JPA API OGM
Could do more explanation of:
https://in.relation.to/2021/06/02/hibernate-orm-550-final-release/
so I can deploy on:
JBoss Bootstrap Environment
JBOSS_HOME: /usr/local/Cellar/wildfly-as/wildfly-preview-25.0.0.Final
JAVA: /Library/Java/JavaVirtualMachines/jdk17.0.1.jdk/Contents/Home/bin/java

Error while running project on Wildfly-datasource DB connection

I'm trying to connect my project to a Database(with Mysql workbench). I have two files:
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
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_2.xsd">
<persistence-unit name="dogs-breeds-jee" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/dogsBreedsEeDS</jta-data-source>
<class>domain.Breed</class>
<exclude-unlisten-classes>true</exclude-unlisten-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.use_sql_comments" value="true"/>
<property name="hibernate.default_batch_fetch_size" value="16"/>
<property name="hibernate.jdbc.batch_size" value="100"/>
<property name="hibernate.order_updates" value="true"/>
<property name="hibernate.id.new_generator_mappings" value="true"/>
</properties>
</persistence-unit>
</persistence>
and an .xml for my datasource:
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns ="http://www.jboss.org/ironjacamar/schema"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation ="
http://www.jboss.org/ironjacamar/schema
http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
<datasource jndi-name="java:jboss/datasources/dogsBreedsEeDS" enabled="true" use-java-context ="true" pool-name="dogsBreedsEeDS">
<connection-url> jdbc:mysql://localhost:3306/java-ee-schema?serverTimezone=UTC</connection-url>
<driver> com.mysql.jdbc.Driver </driver>
<security>
<user-name> java--client </user-name>
<password> password </password>
</security>
</datasource>
</datasources>
I've done the mapping in my model and if everything is okay it should create a db in my java-ee-schema right?
but I'm getting these errors when I run my WildFly server:
658 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 44) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "mysql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [com.mysql]"
799 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "dogs-breeds-jee-ds.xml")]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.com_mysql_jdbc_Driver"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.data-source.\"jboss.naming.context.java.jboss.datasources.dogsBreedsEeDS\" is missing [jboss.jdbc-driver.com_mysql_jdbc_Driver]"]
}
946 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: WildFly Full 20.0.1.Final (WildFly Core 12.0.3.Final) started (with errors) in 6638ms - Started 454 of 688 services (3 services failed or missing dependencies, 378 services are lazy, passive or on-demand)
Can someone tell me why is this happening? Am I doing something wrong?
Thanks a lot
You need to define your driver in the configuration. The "driver" tag doesn't target a class but a name in wildfly configuration.

Problems creating Wildfly 10 datasource

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.

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.

karaf - mongodb - com.mongodb.Mongo - ClassNotFoundException

I would like to use mongodb component in my camelContext. I have already installed feature camel-mongodb in karaf and when I do bundle:list I get
156 | Active | 50 | 2.11.3.RELEASE | MongoDB Java Driver
To show Mongo Java Drivers are installed and running.Here's my camelContext
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring-2.0.0.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<!-- <camelContext xmlns="http://camel.apache.org/schema/blueprint"> -->
<route>
<from uri="rabbitmq://localhost:5672/A?username=guest&password=guest&autoDelete=false&routingKey=source_q&queue=source_q&exchangeType=topic"/>
<bean ref="myTransform" method="transform"/>
<to uri="mongodb:mongo?database=mongo_poc&collection=camel&operation=save"/>
</route>
</camelContext>
<!-- Mongo DB -->
<bean id="mongo" class="com.mongodb.Mongo">
<constructor-arg index="0" value="localhost" />
</bean>
</beans>
When I deploy this exception, I get following exception
karaf#root()> Exception in thread "SpringOsgiExtenderThread-8" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'camel-3': Invocation of init method failed; ne
sted exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.mongodb.Mongo] for bean with name 'mongo' defined in URL [bundle://149.23:0/META-INF/spring/
camelContext.xml]; nested exception is java.lang.ClassNotFoundException: com.mongodb.Mongo not found from bundle [demo.camel-bundle]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.mongodb.Mongo] for bean with name 'mongo' defined in URL [bundle://149.23:0/META-INF/spring/camelCo
ntext.xml]; nested exception is java.lang.ClassNotFoundException: com.mongodb.Mongo not found from bundle [demo.camel-bundle]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1275)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:575)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1344)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:355)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:334)
at org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1178)
at org.apache.camel.spring.CamelContextFactoryBean.getBeanForType(CamelContextFactoryBean.java:188)
at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.afterPropertiesSet(AbstractCamelContextFactoryBean.java:145)
at org.apache.camel.osgi.CamelContextFactoryBean.afterPropertiesSet(CamelContextFactoryBean.java:64)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
... 14 more
Caused by: java.lang.ClassNotFoundException: com.mongodb.Mongo not found from bundle [demo.camel-bundle]
at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:103)
at org.springframework.osgi.util.BundleDelegatingClassLoader.loadClass(BundleDelegatingClassLoader.java:156)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:260)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:416)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1296)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1267)
... 24 more
Caused by: java.lang.ClassNotFoundException: com.mongodb.Mongo not found by demo.camel-bundle [149]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1844)
at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:937)
at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:99)
... 30 more
I have also included
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.11.3</version>
</dependency>
in the pom.xml of my camel-bundle project
Please help me. I am not sure what is missing here.
I fixed this by adding the required package in the pom.xml of by camel bundle project under the <Import-Package> tag
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.3</version>
<!--
| the following instructions build a simple set of public/private classes into an OSGi bundle
-->
<configuration>
<instructions>
<Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
<Bundle-Version>${pom.version}</Bundle-Version>
<Import-Package>com.mongodb, demo.service;version="${pom.version}"
^^^^^^^^^^^ </Import-Package>
<Include-Resource>src/main/resources</Include-Resource>
</instructions>
</configuration>
</plugin>