Unable to resolve JPA persistence unit in Java EE application using AxonFramework

1,835 views
Skip to first unread message

pa...@pholding.co.uk

unread,
Apr 2, 2015, 7:05:21 PM4/2/15
to axonfr...@googlegroups.com
I've created a simple project so that I can experiment with AxonFramework running in a Java EE 7 environment, but when I try to deploy the EAR file to the application server, the deployment fails with the error message "Could not resolve a persistence unit corresponding to the persistence-context-ref-name [org.axonframework.common.jpa.ContainerManagedEntityManagerProvider/entityManager] in the scope of the module called [cqrsdemo-ear#cqrsdemo-web-0.0.1-SNAPSHOT.war]". 

The project is comprised of an EAR module which contains an EJB module and WAR module. The EJB module is basically an adaptation of the "To Do Item" quick start tutorial, but without the test fixtures and instead the ToDoItemCreatedEvent and ToDoItemCompletedEvent events invoke the JPA entity manager to insert/update records into an Oracle database. Within the EAR module is a singleton class that is invoked on startup to initialize the AxonFramework (i.e. command bus, command gateway, event bus, event respository, etc). The WAR module is a very simple JSF web based application that calls a the singleton class in the EJB module and invokes the CreateToDoItemCommand and MarkCompletedCommand commands.

What I don't understand is why AxonFramework is causing this error to be thrown given that the war module referenced in the error message does not use JPA.

Is anyone able to suggest where I might be going wrong or give me some pointers to resolve this issue please?

The full error from the server log file is as follows:

[2015-04-02T22:41:09.473+0100] [glassfish 4.0] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=35 _ThreadName=admin-listener(1)] [timeMillis: 1428010869473] [levelValue: 1000] [[
  Exception while preparing the app : Could not resolve a persistence unit corresponding to the persistence-context-ref-name [org.axonframework.common.jpa.ContainerManagedEntityManagerProvider/entityManager] in the scope of the module called [cqrsdemo-ear#cqrsdemo-web-0.0.1-SNAPSHOT.war]. Please verify your application.
java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [org.axonframework.common.jpa.ContainerManagedEntityManagerProvider/entityManager] in the scope of the module called [cqrsdemo-ear#cqrsdemo-web-0.0.1-SNAPSHOT.war]. Please verify your application.
at com.sun.enterprise.deployment.BundleDescriptor.findReferencedPUViaEMRef(BundleDescriptor.java:727)
at com.sun.enterprise.deployment.BundleDescriptor.findReferencedPUsViaPCRefs(BundleDescriptor.java:715)
at org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl.findReferencedPUs(WebBundleDescriptorImpl.java:996)
at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:186)
at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:922)
at org.glassfish.javaee.full.deployment.EarDeployer.prepareBundle(EarDeployer.java:307)
at org.glassfish.javaee.full.deployment.EarDeployer.access$200(EarDeployer.java:88)
at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:153)
at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:150)
at org.glassfish.javaee.full.deployment.EarDeployer.doOnBundles(EarDeployer.java:230)
at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllTypedBundles(EarDeployer.java:239)
at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllBundles(EarDeployer.java:265)
at org.glassfish.javaee.full.deployment.EarDeployer.prepare(EarDeployer.java:150)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:922)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:431)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:356)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:235)
at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:257)
at org.glassfish.admin.rest.resources.TemplateListOfResource.createResource(TemplateListOfResource.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:125)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:91)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:346)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:341)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:101)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:224)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:198)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:946)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:331)
at org.glassfish.admin.rest.adapter.RestAdapter$2.service(RestAdapter.java:318)
at org.glassfish.admin.rest.adapter.RestAdapter.service(RestAdapter.java:181)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:744)
]]

[2015-04-02T22:41:09.708+0100] [glassfish 4.0] [INFO] [] [org.glassfish.admingui] [tid: _ThreadID=241 _ThreadName=admin-listener(13)] [timeMillis: 1428010869708] [levelValue: 800] [[
  Exception Occurred :Error occurred during deployment: Exception while preparing the app : Could not resolve a persistence unit corresponding to the persistence-context-ref-name [org.axonframework.common.jpa.ContainerManagedEntityManagerProvider/entityManager] in the scope of the module called [cqrsdemo-ear#cqrsdemo-web-0.0.1-SNAPSHOT.war]. Please verify your application.. Please see server.log for more details.
Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method : java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [org.axonframework.common.jpa.ContainerManagedEntityManagerProvider/entityManager] in the scope of the module called [cqrsdemo-ear#cqrsdemo-web-0.0.1-SNAPSHOT.war]. Please verify your application.
Could not resolve a persistence unit corresponding to the persistence-context-ref-name [org.axonframework.common.jpa.ContainerManagedEntityManagerProvider/entityManager] in the scope of the module called [cqrsdemo-ear#cqrsdemo-web-0.0.1-SNAPSHOT.war]. Please verify your application.     Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method : java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [org.axonframework.common.jpa.ContainerManagedEntityManagerProvider/entityManager] in the scope of the module called [cqrsdemo-ear#cqrsdemo-web-0.0.1-SNAPSHOT.war]. Please verify your application.
Could not resolve a persistence unit corresponding to the persistence-context-ref-name [org.axonframework.common.jpa.ContainerManagedEntityManagerProvider/entityManager] in the scope of the module called [cqrsdemo-ear#cqrsdemo-web-0.0.1-SNAPSHOT.war]. Please verify your application.]]

Allard Buijze

unread,
Apr 3, 2015, 8:22:04 AM4/3/15
to Axon Framework Users
Hi,

it's not Axon throwing the exception, but Glassfish. It probably recognizes the @PersistenceContext annotation used in the ContainerManagedEntityManagerProvider class. If you don't use JPA, you don't need that class anyway. I am not sure how, but there must be a way to tell the application container to ignore this class. In fact, it doesn't need to scan the org.axonframework package at all.

Cheers,

Allard

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

fredgate

unread,
Mar 19, 2019, 12:58:36 PM3/19/19
to Axon Framework Users
This thread is old, but I have the same error.
I don't use Jpa with Axon, but I have another part of application that uses JPA, so I have a persistence.xml file.
Glassfish seems to look for PersistenceContext annotation, in order to automatically instantiate these classes.
Has anyone an idea to exclude axon classes from this scanning ?

bert.l...@axoniq.io

unread,
Mar 20, 2019, 11:40:54 AM3/20/19
to Axon Framework Users
Fred,
AFAIK the beans.xml file is the one which controls the scanning mode for CDI, but for PersistenceContext and other JEE components, you have to use Application Server specific configuration at WAR or EAR level. Most likely it is a custom XML file WEB-INF or META-INF respectively.

For Glassfish the file to look at would be glassfish-application.xml or glassfish-web.xml, where you can use something like "<scanning-exclude>axon-*</scanning-exclude>". I haven't had the problem so I never tried it, but that sounds like the way to go.

BTW In the current release of the Framework this annotation (PersistenceContext) is no longer used in the core jars, but can be found in the spring-boot module.

Cheers,
Bert Laverman
Reply all
Reply to author
Forward
0 new messages