This discussion is archived
2 Replies Latest reply: Sep 13, 2013 9:28 AM by anemdhana RSS

Unable to retrieve EntityManagerFactory for unitName primary

anemdhana Newbie
Currently Being Moderated


this is the exception thrown when injecting EntityManager.

Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName primary at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(


The following exists in ejb module of my maven project.

public class Resources {

    @PersistenceContext(unitName = "primary")
    private EntityManager em;


My persistence unit below in the location ejb/src/main/resources/META-INF


<persistence-unit name="primary">
      <!-- If you are running in a production environment, add a managed 
         data source, this example data source is just for development and testing! -->
      <!-- The datasource is deployed as <EAR>/META-INF/glassfish-resources.xml, you
         can find it in the source at ear/src/main/application/META-INF/glassfish-resources.xml -->

Pls help me what could be missing in my code.


  • Correct Answers - 10 points
  • Helpful Answers - 5 points