0

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:

enter image description here

My JPA Subsystem's default datasource is configured as java:/jboss/db

I have it listed as a persistence unit in WildFly:

enter image description here

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ben
  • 843
  • 2
  • 9
  • 20
  • 1
    The error indicated that it can't find/load the MS SQL driver. It seems that you are using JTDS. Can you check this post and its solution: https://stackoverflow.com/questions/20190703/jtds-module-under-wildfly-jboss – Korgen May 30 '16 at 05:58

2 Answers2

1

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.

Community
  • 1
  • 1
VeenarM
  • 1,263
  • 1
  • 10
  • 14
  • I have fixed that small error I was getting, but now I get `javax.persistence.PersistenceException: No Persistence provider for EntityManager named WebApplication1PU at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)` trying to run JPQL queries. My persistence manager seems to deploy yet my war is marked as not being persistent. – Ben May 30 '16 at 10:47
  • I just started from scratch to try and get it to work and now I get in my JPQL query window: `java.lang.Exception: You need to specify either database connection or datasource in persistence.xml` I have done this and I have cleaned and built the persistence.xml with the correct datasource in NetBeans and deployed it. I can see the persistence unit in WildFly and my datasource test works but my .war deployment is marked as not being persistent. – Ben May 30 '16 at 11:26
  • Where is your persistence located? should be /META-INF/ verify your datasource is bound to the same jndi – VeenarM May 31 '16 at 03:03
-1

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"/>
KlajdPaja
  • 959
  • 1
  • 8
  • 17
  • He's doing a JNDI lookup on the datasource defined within WildFly, That's why he doesn't need those settings. – Korgen May 30 '16 at 05:53
  • more over storing your user/passwords in files that are deployed with your app is a security issue and should always be avoided.. – VeenarM Jun 19 '16 at 10:27