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.
Related
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
We are facing issue in our application with respect to the persistence configuration. The application runs on TomEE Plus (7.0) and uses Open JPA implementation. Below is the error which we are getting
<openjpa-2.4.2-r422266:1777108 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: <openjpa-2.4.2-r422266:1777108 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "oracle.jdbc.xa.client.OracleXADataSource" and URL "jdbc:oracle:thin:#//mydburl.abc.com:1881/MYSID.ABC.COM". You may have specified an invalid URL.
We dont' get the above error when using oracle.jdbc.driver.OracleDriver. The XA driver settings were working fine on IBM WebSphere 8.5. Is there anything else which we need to configure in TomEE+ to get it working?
Update
Adding the persistence.xml file as well
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="MySchema" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>myjndi</jta-data-source>
<class>com.abc.jpa.entity.Tuser</class>
<class>com.abc.jpa.entity.Taddress</class>
<properties>
<property name="tomee.jpa.factory.lazy" value="true"></property>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.xa.client.OracleXADataSource" />
<property name="javax.persistence.jdbc.url"
value="jdbc:oracle:thin:#//mydburl.abc.com:1881/MYSID.ABC.COM" />
<property name="javax.persistence.jdbc.user" value="userName" />
<property name="javax.persistence.jdbc.password" value="password" />
</properties>
</persistence-unit>
</persistence>
As mentioned, it works fine if I use oracle.jdbc.driver.OracleDriver as the jdbc driver class
I have a problem with my jpa project.
Already found this thread:
JPA: configure persistence provider
My persistence.xml is at:
C:\workspace\DevWorkSample\src\META-INF
so this seems to be correct.
My persistence.xml looks like this:
<?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" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="CustomerQuery">
<jta-data-source>java:comp/env/jdbc/MyDataSource</jta-data-source>
<class>myjpa.CustomerAcct</class>
<!-- exclude-unlisted-classes>true</exclude-unlisted-classes -->
<properties>
<property name="openjpa.LockTimeout" value="30000" />
<property name="openjpa.jdbc.TransactionIsolation" value="read-committed" />
<property name="openjpa.Log" value="none" />
<property name="openjpa.jdbc.UpdateManager" value="operation-order" />
<property name="openjpa.ConnectionURL" value="DB URL"/>
<property name="openjpa.ConnectionDriverName" value="Driver Name"/>
<property name="openjpa.ConnectionUserName" value="userid"/>
<property name="openjpa.ConnectionPassword" value="password"/>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
</properties>
</persistence-unit>
</persistence>
Errors:
1.
An error occurred in the com.ibm.websphere.persistence.PersistenceProviderImpl persistence provider when it attempted to create the container entity manager factory for the CustomerQuery persistence unit. The following error occurred: There was an error when invoking the static newInstance method on the named factory class "com.ibm.ws.persistence.jdbc.kernel.WsJpaJDBCBrokerFactory". See the nested exception for details.
2.
For the [com.ibm.devworks.Deposit] servlet, com.ibm.devworks.Deposit servlet class was found, but a resource injection failure has occurred. CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/com.ibm.devworks.Deposit/emf reference. The exception message was: <openjpa-2.2.3-SNAPSHOT-r422266:1642995 fatal general error> org.apache.openjpa.persistence.PersistenceException: There was an error when invoking the static newInstance method on the named factory class "com.ibm.ws.persistence.jdbc.kernel.WsJpaJDBCBrokerFactory". See the nested exception for details.
What do I have to change to fix this?
I am deploying a simple web application to WildFly 10 from NetBeans to try and teach myself Java EE. However, I get the following error when trying to run a jpql query from NetBeans:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named WebApplication1PU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
This is despite the fact that I have defined a persistence provider. This is my persistence.xml:
<?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="WebApplication1PU" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/jboss/db</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2012Dialect"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
When I test my datasource in WildFly it works:
My JPA Subsystem's default datasource is configured as java:/jboss/db
I have it listed as a persistence unit in WildFly:
I am using JTDS driver for MS SQL Server and I do get this error on startup of the server that I can't get rid of:
10:33:07,600 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "JTDS")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [net.sourceforge.jtds]"
However, as I said, testing the datasource works, so this shouldn't matter. Can anyone help me?
As a comment mentioned, it's saying Wildfly cannot find the provider module.
Download: https://sourceforge.net/projects/jtds/files/jtds/1.3.1/jtds-1.3.1-dist.zip/download - which is the jtds JDBC driver,
and install it into the /modules directory of wildfly.
You can launch the ./jboss-cli.sh to install modules.
See: JTDS module under WildFly (JBoss)
Give a bit more insight into it.
This URL: http://www.mastertheboss.com/jboss-server/jboss-datasource/configuring-a-datasource-with-postgresql-and-jboss-wildfly
Has how to install postgres jdbc drivers into wildfly, but it's effectively the same process for other JDBC drivers, just package name change etc.
In persistence-unit properties you are missing the following
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/mydb"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="dbroot"/>
<property name="hibernate.connection.password" value="password"/>
I am trying to create a test application that accesses a postgres database using JavaEE and Wildly 9.
So I downloaded Wildfly 9 and followed these instructions to add the driver to it. When I run
/subsystem=datasources:installed-drivers-list
I get
{
"driver-name" => "postgresql-9.4-1201.jdbc41.jar",
"deployment-name" => "postgresql-9.4-1201.jdbc41.jar",
"driver-module-name" => undefined,
"module-slot" => undefined,
"driver-datasource-class-name" => undefined,
"driver-xa-datasource-class-name" => undefined,
"driver-class-name" => "org.postgresql.Driver",
"driver-major-version" => 9,
"driver-minor-version" => 4,
"jdbc-compliant" => false
}
so it seems ok.
I also copied the jar ( postgresql-9.4-1201.jdbc41.jar ) file to the deployment folder in Wildfly.
I added this dependency to my pom.xml:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
</dependency>
and this is my persistence.xml:
<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="postgres">
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/test" />
<property name="hibernate.connection.username" value="test" />
<property name="hibernate.connection.password" value="test" />
<!-- <property name="hibernate.show_sql" value="true"/>
<property name="hibernate.flushMode" value="FLUSH_AUTO" />
<property name="hibernate.hbm2ddl.auto" value="update" />-->
</properties>
</persistence-unit>
</persistence>
But overtime I try to run my application I get:
java.lang.ClassNotFoundException: Could not load requested class :
org.postgresql.Driver
What am I missing? I can't find any other procedure to do in order to make it work. I am sitting in this problem for some hours now and I can't see anything else I can do.
edit: I created a data source and it works (so the dependencies are all there, there must be something wrong with the persistence.xml itself). I would rather have it working using the persistence.xml file, due to configurability.
here is my datasource as configured in the standalone.xml
<datasource jta="true" jndi-name="java:/PostgresDS" pool-name="PostgresDS" enabled="true" use-ccm="true">
<connection-url>jdbc:postgresql://localhost:5432/stats</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgresql</driver>
<security>
<user-name>test</user-name>
<password>test</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>