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");

<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 of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.