javax.persistence.PersistenceException: No Persistence provider for EntityManager named ... in JBoss EAP 6

Solution Unverified - Updated -

Issue

  • We have a security login module where we are trying to use JPA / Hibernate EntityManager to read from a database. We have our login module inside of a custom module which depends on jpa and hibernate modules as shown below. But we are getting the error 'javax.persistence.PersistenceException: No Persistence provider for EntityManager named' when trying to get the EntityManagerFactory via:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("SecurityPersistenceUnit");
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.examples.security.exampleLoginModule">
  <resources>
    <resource-root path="example-security-login-module.jar"></resource>
  </resources>
  <dependencies>
     <module name="javax.api" export="false"></module>
     <module name="javax.persistence.api" ></module>
     <module name="org.hibernate" ></module>
     <module name="org.picketbox"></module>
     <module name="org.jboss.logging" ></module>
  </dependencies>
</module>
ERROR [com.example.ExampleLoginModule] (http-localhost/127.0.0.1:8080-1) Failed to create principal: javax.persistence.PersistenceException: No Persistence provider for EntityManager named SecurityPersistenceUnit
  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) [hibernate-jpa-2.0-api-1.0.1.Final-redhat-2.jar:1.0.1.Final-redhat-2]
  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) [hibernate-jpa-2.0-api-1.0.1.Final-redhat-2.jar:1.0.1.Final-redhat-2]
  at com.example.service.ExampleSecurityProfile.getEMF(ExampleSecurityProfile.java:21) [example-saml-security.jar:]

Environment

Red Hat JBoss Enterprise Application Platform (EAP) 6.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content