EntityManager Missing When Restarting Application on WebLogic 12
===

I have an application which uses JPA. I have successfully deployed this application on WebLogic 12c. 

I startup my server, deploy my application and off we go.

In my various @Stateless EJBs I have @PersistenceContext(unitName = "MyJpa") and expect the container to inject the EntityManager. 

In my persistence.xml i configure my provider:

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>myDs</jta-data-source>


This works fine in the scenario described above.

If I restart my (managed) server everything is still fine.

But if I restart just the application, something goes wrong. I don't see any problems at startup but when I hit one of my webservices which in return hits one of my beans with @PersistenceContext I get an error (see below).

It seems like it cannot find an appropriate bean to inject as my EntityManager. This seems completely crazy to me - isn't this bean supposed to be managed by the container???

I am at a loss here - suggestions, please !?!

SEVERE: EJB Exception: : com.bea.core.repackaged.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FetchImpl': Initialization of bean failed; nested exception is com.bea.core.repackaged.springframework.beans.factory.BeanCreationException: Dependency injection failure: can't find the bean definition about class interface javax.persistence.EntityManager; nested exception is com.bea.core.repackaged.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManager] is defined: No beans of type javax.persistence.EntityManager; owner=com.bea.core.repackaged.springframework.context.support.GenericApplicationContext@135924c: display name [com.bea.core.repackaged.springframework.context.support.GenericApplicationContext@135924c]; startup date [Fri Jul 13 22:05:23 CEST 2012]; parent: com.bea.core.repackaged.springframework.context.support.GenericApplicationContext@8cf25e
	at com.bea.core.repackaged.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)
	at com.bea.core.repackaged.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.bea.core.repackaged.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
	at com.bea.core.repackaged.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)
	at com.bea.core.repackaged.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
	at com.bea.core.repackaged.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
	at com.bea.core.repackaged.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:308)
	at com.bea.core.repackaged.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:297)
	at com.bea.core.repackaged.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:942)
	at com.bea.core.repackaged.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:224)
	at com.bea.core.repackaged.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:228)
	at com.oracle.pitchfork.inject.Jsr250Metadata.getUniqueInstanceOfType(Jsr250Metadata.java:349)
	at com.oracle.pitchfork.inject.Jsr250Metadata.resolveByType(Jsr250Metadata.java:345)
	at com.oracle.pitchfork.inject.Jsr250Metadata.resolve(Jsr250Metadata.java:275)
	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.BaseWSLocalObject.__WL_preInvoke(BaseWSLocalObject.java:117)
	at com.wmdata.examdb.webservice.ExDbRequestWSBean_alg8qo_WSOImpl.__WL_getChallenge_WS_preInvoke(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at weblogic.wsee.server.ejb.WsEjb.preInvoke(WsEjb.java:49)
	at weblogic.wsee.jaxws.WLSEjbInstanceResolver$WLSEjbInvoker.invoke(WLSEjbInstanceResolver.java:193)
	at weblogic.wsee.jaxws.WLSInstanceResolver$WLSInvoker.invoke(WLSInstanceResolver.java:74)
	at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:149)
	at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:95)
	at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:892)
	at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:841)
	at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:804)
	at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:706)
	at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:430)
	at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:640)
	at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:265)
	at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:163)
	at weblogic.wsee.jaxws.WLSServletAdapter.handle(WLSServletAdapter.java:171)
	at weblogic.wsee.jaxws.HttpServletAdapter$AuthorizedInvoke.run(HttpServletAdapter.java:708)
	at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
	at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
	at weblogic.wsee.util.ServerSecurityHelper.authenticatedInvoke(ServerSecurityHelper.java:103)
	at weblogic.wsee.jaxws.HttpServletAdapter$3.run(HttpServletAdapter.java:311)
	at weblogic.wsee.jaxws.HttpServletAdapter.post(HttpServletAdapter.java:336)
	at weblogic.wsee.jaxws.JAXWSServlet.doRequest(JAXWSServlet.java:99)
	at weblogic.servlet.http.AbstractAsyncServlet.service(AbstractAsyncServlet.java:99)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
	at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242)
	at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:216)
	at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:132)
	at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:352)
	at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:235)
	at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3284)
	at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3254)
	at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
	at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
	at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
	at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2163)
	at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2089)
	at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2074)
	at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1512)
	at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
	at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
	at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: com.bea.core.repackaged.springframework.beans.factory.BeanCreationException: Dependency injection failure: can't find the bean definition about class interface javax.persistence.EntityManager; nested exception is com.bea.core.repackaged.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManager] is defined: No beans of type javax.persistence.EntityManager; owner=com.bea.core.repackaged.springframework.context.support.GenericApplicationContext@135924c: display name [com.bea.core.repackaged.springframework.context.support.GenericApplicationContext@135924c]; startup date [Fri Jul 13 22:05:23 CEST 2012]; parent: com.bea.core.repackaged.springframework.context.support.GenericApplicationContext@8cf25e
	at com.oracle.pitchfork.inject.Jsr250Metadata.applyInjections(Jsr250Metadata.java:234)
	at com.oracle.pitchfork.inject.Jsr250Metadata.inject(Jsr250Metadata.java:219)
	at com.oracle.pitchfork.inject.Jsr250Metadata.injectAndPostConstruct(Jsr250Metadata.java:246)
	at com.oracle.pitchfork.inject.Jsr250MetadataBeanPostProcessor.postProcessAfterInstantiation(Jsr250MetadataBeanPostProcessor.java:40)
	at com.bea.core.repackaged.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:957)
	at com.bea.core.repackaged.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
	... 74 more
Caused by: com.bea.core.repackaged.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManager] is defined: No beans of type javax.persistence.EntityManager; owner=com.bea.core.repackaged.springframework.context.support.GenericApplicationContext@135924c: display name [com.bea.core.repackaged.springframework.context.support.GenericApplicationContext@135924c]; startup date [Fri Jul 13 22:05:23 CEST 2012]; parent: com.bea.core.repackaged.springframework.context.support.GenericApplicationContext@8cf25e
	at com.oracle.pitchfork.inject.Jsr250Metadata.getUniqueInstanceOfType(Jsr250Metadata.java:351)
	at com.oracle.pitchfork.inject.Jsr250Metadata.resolveByType(Jsr250Metadata.java:345)
	at com.oracle.pitchfork.inject.Jsr250Metadata.resolve(Jsr250Metadata.java:275)
	at com.oracle.pitchfork.inject.Jsr250Metadata.applyInjections(Jsr250Metadata.java:228)
	... 79 more