'IllegalArgumentException: No persistence unit' Error When Application Deployed From 12c OEPE (Doc ID 1400524.1)

Last updated on AUGUST 16, 2016

Applies to:

Oracle Weblogic Server - Version 12.1.1.0 and later
Oracle TopLink - Version 11.1.1.6.0 and later
Information in this document applies to any platform.

Symptoms

Using  Oracle Enterprise Pack for Eclipse (10.3.x / 12c OEPE),   a J2EE application is  developed,   deployed  into 12.1.1 WLS  server.

When invoking  servlet of this application, the following exception is occuring :

java.lang.IllegalArgumentException: No persistence unit named 'laadmin' is available in scope Test. Available persistence units: []
at weblogic.persistence.ModulePersistenceUnitRegistry.getPersistenceUnit(ModulePersistenceUnitRegistry.java:130)
at weblogic.persistence.BasePersistenceContextProxyImpl.(BasePersistenceContextProxyImpl.java:40)
at weblogic.persistence.TransactionalEntityManagerProxyImpl.(TransactionalEntityManagerProxyImpl.java:31)
at weblogic.persistence.EntityManagerInvocationHandlerFactory.createTransactionalEntityManagerInvocationHandler(EntityManagerInvocationHandlerFactory.java:20)
at weblogic.persistence.PersistenceManagerObjectFactory.createPersistenceContextProxy(PersistenceManagerObjectFactory.java:66)
at com.oracle.injection.integration.ModuleInjectionArchive$DefaultPersistenceContextProxyFactory.createPersistenceContextProxy(ModuleInjectionArchive.java:245)



The servlet is invoking an EJB (TestEJB) embedded in the web application
and using JPA persistent unit (defined via @PersistenceContext(unitName="laadmin")) to get an entity as the following  :


@WebServlet("/test")
public class TestServlet extends HttpServlet {

@PersistenceContext(unitName="laadmin")
private EntityManager em;
@Inject private TestEJB testEJB;

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

Test test = em.find(Test.class, 1);
if (test == null) {
resp.getWriter().print("Not Found!!!");
} else {
resp.getWriter().print(test.getTestName());

testEJB.listThem();

resp.getWriter().print("finished running query");
}
}
}

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms