2 Replies Latest reply: Aug 19, 2013 8:49 AM by noechri RSS

    Weblogic 12c not picking up persistence unit in WAR

    933870
      I'm trying to get an example CRUD application to run on WebLogic 12c (for the app see: http://henk53.wordpress.com/2012/04/15/jsf2-primefaces3-ejb3-jpa2-integration-project/)

      So far the applications runs on JBoss AS 7.1, GlassFish 3.1.2 and TomEE beta 2. In all those application servers persistence.xml is picked-up, and processed so I'm at a loss what's wrong with WebLogic. I'm using Eclipse 3.7.2 and the Oracle WebLogic 12C WTP server adapter for the deployment.

      I'm getting the following exception:

      java.lang.IllegalArgumentException: No persistence unit named 'entityManager' is available in scope jsf_ejb_jpa. Available persistence units: []
           at weblogic.persistence.ModulePersistenceUnitRegistry.getPersistenceUnit(ModulePersistenceUnitRegistry.java:130)
           at weblogic.persistence.BasePersistenceContextProxyImpl.<init>(BasePersistenceContextProxyImpl.java:40)
           at weblogic.persistence.TransactionalEntityManagerProxyImpl.<init>(TransactionalEntityManagerProxyImpl.java:31)
           at weblogic.persistence.EntityManagerInvocationHandlerFactory.createTransactionalEntityManagerInvocationHandler(EntityManagerInvocationHandlerFactory.java:20)
           at weblogic.persistence.PersistenceManagerObjectFactory.createPersistenceContextProxy(PersistenceManagerObjectFactory.java:66)
           at weblogic.persistence.PersistenceManagerObjectFactory.getObjectInstance(PersistenceManagerObjectFactory.java:31)
           at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
           at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:251)
           at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:406)
           at weblogic.j2eeclient.java.ClientReadOnlyContextWrapper.lookup(ClientReadOnlyContextWrapper.java:35)
           at weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.java:130)
           at javax.naming.InitialContext.lookup(InitialContext.java:392)
           at javax.naming.InitialContext.doLookup(InitialContext.java:265)
           at com.oracle.pitchfork.inject.Jsr250Metadata.jndiLookup(Jsr250Metadata.java:307)
           at com.oracle.pitchfork.inject.Jsr250Metadata.resolveByName(Jsr250Metadata.java:303)
           at com.oracle.pitchfork.inject.Jsr250Metadata.resolve(Jsr250Metadata.java:266)
           at com.oracle.pitchfork.inject.Jsr250Metadata.applyInjections(Jsr250Metadata.java:228)
           at com.oracle.pitchfork.inject.Jsr250Metadata.inject(Jsr250Metadata.java:219)
           at com.oracle.pitchfork.spi.BaseComponentBrokerImpl.getBean(BaseComponentBrokerImpl.java:63)
           at com.oracle.pitchfork.spi.EjbComponentCreatorBrokerImpl.getBean(EjbComponentCreatorBrokerImpl.java:33)
           at weblogic.ejb.container.injection.EjbComponentCreatorImpl.getBean(EjbComponentCreatorImpl.java:76)
           at weblogic.ejb.container.manager.BaseEJBManager.createNewBeanInstance(BaseEJBManager.java:209)
           at weblogic.ejb.container.manager.BaseEJBManager.allocateBean(BaseEJBManager.java:235)
           at weblogic.ejb.container.manager.StatelessManager.createBean(StatelessManager.java:293)
           at weblogic.ejb.container.pool.StatelessSessionPool.createBean(StatelessSessionPool.java:185)
           at weblogic.ejb.container.pool.StatelessSessionPool.getBean(StatelessSessionPool.java:114)
           at weblogic.ejb.container.manager.StatelessManager.preInvoke(StatelessManager.java:174)
           at weblogic.ejb.container.internal.BaseLocalObject.getBeanInstance(BaseLocalObject.java:146)
           at weblogic.ejb.container.internal.BaseLocalObject.preInvoke(BaseLocalObject.java:103)
           at weblogic.ejb.container.internal.BaseLocalObject.__WL_preInvoke(BaseLocalObject.java:67)
           at weblogic.ejb.container.internal.SessionLocalMethodInvoker.invoke(SessionLocalMethodInvoker.java:20)
           at com.example.dao.jpa.JpaUserDAO_wrkew_UserDAOImpl.add(Unknown Source)
           at com.example.backing.IndexBacking.addUser(IndexBacking.java:38)

      Notice that "entityManager" is the name of the instance variable in which injection is being performed:

      @PersistenceContext(name="example")
      private EntityManager entityManager;

      If I rename this variable to "em: as follows:

      @PersistenceContext(name="example")
      private EntityManager em;

      Then, lo and behold, the exception changes into:

      java.lang.IllegalArgumentException: No persistence unit named 'em' is available in scope jsf_ejb_jpa. Available persistence units: []

      As the example uses a data-source defined in web.xml, which is only marginally supported in most application servers, I tried to define a WebLogic specific application scoped data-source instead and let the persistence unit use that. I couldn't find a way to do this in a .war (is this even possible?), so I created an .ear archive instead. When deploying the EAR, the data-source is clearly being created, but I'm getting the same exception again.

      I finally created an EJB module with a persistence.xml and a simple Singleton that's injected with the entityManager, and added that to the EAR. This works for the EJB module, but in the web module injection of the other entity manager still fails.

      Any idea what might be the problem?
        • 1. Re: Weblogic 12c not picking up persistence unit in WAR
          933870
          After some more fiddling, I discovered it's not WebLogic itself that's at fault here, but most likely Oracle's WTP adapter. Apparently it doesn't include persistence.xml in the archive that gets deployed. When I export the project as an .ear archive and copy this to WebLogic's autodeploy directly, things do work.

          I tried to find out what the main difference was between the deployments, but I could not find where the Oracle WTP adapter creates the deployment. I tried to test where a resource inside the EAR resides on the filesystem via the following code inside a backing bean:

          URL url = Thread.currentThread().getContextClassLoader().getResource("com/example/backing");

          It looks like there isn't a real .war or .ear being created and deployed, but there's a link back to the workspace, as the URL resolves to:

          file:/Users/henk/eclipse37ee/workspace/jsf_ejb_jpa/build/classes/com/example/backing/

          If I execute the same code for the ear in the autodeploy folder, the URL resolves to some jar inside:

          /Users/henk/eclipse37ee/wls1211_dev/mydomain/servers/myserver/tmp/_WL_user/_appsdir_jsf_ejb_jpa_ear_ear/2jzks6/war/WEB-INF/lib/

          In case of the WTP 'deployment' linking back to the Eclipse workspace, META-INF/persistence.xml is actually there too, but for some reason Weblogic can't find it there?

          Edited by: Henk on Apr 29, 2012 2:57 PM
          • 2. Re: Weblogic 12c not picking up persistence unit in WAR
            noechri

            Hello,

             

            Have you found a solution for this ?  I'm experiencing the same problem.

            Deploying my maven build .ear using the console works fine, but if i deploy using the Weblogic 12C adaptor , i get the error :

             

            'java.lang.IllegalArgumentException: No persistence unit named '***' is available in scope ***. Available persistence units: []'

             

            grtz,