Share persistence.xml file between two EJB modules in EAR
marcos_aps Jul 12, 2010 3:14 PMJBoss 6.0.0 M3
Hello, everybody!
I have two EJB modules in an EAR module. I would like to know how to share a single persistence.xml file with these two EJB modules. If I replicate the persistence.xml file in the two EJB modules, the EAR project deploys ok, but of course that's not what we want. If I remove the persistence.xml file from any of the EJB projects, the EAR doesn't deploy properly. I'm stuck with this. I've already tried many kind of configurations but none worked. I really would like to have some help with this issue to proceed working. This is my EAR structure:
solicitacoes-ejb.jar (EJB session beans)
solicitacoes-dao.jar (EJB interfaces)
solicitacoes-dao-jpa.jar (EJB session beans)
solicitacoes-ejbClient.jar (entities and EJB interfaces)
solicitacoes-web.war
META-INF/
This is my application.xml file:
<?xml version="1.0" encoding="UTF-8"?> <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5"> <display-name>solicitacoes-ear</display-name> <module> <ejb>solicitacoes-ejb.jar</ejb> </module> <module> <ejb>solicitacoes-dao-jpa.jar</ejb> </module> <module> <web> <web-uri>solicitacoes-web.war</web-uri> <context-root>solicitacoes</context-root> </web> </module> </application>
If I remove the persistence.xml file from one of the EJB modules, let's say solicitacoes-dao-jpa.jar, I get this error when deploying the EAR file:
16:09:44,062 ERROR [Ejb3Deployment] Exception while processing container metadata for EJB: LocalizadorSetoresDAOBean in unit: solicitacoes-dao-jpa.jar 16:09:44,078 ERROR [AbstractKernelController] Error installing to Real: name=vfs:///C:/jboss-6.0.0.20100429-M3/server/default/deploy/solicitacoes-ear.ear state=PreReal mode=Manual requiredState=Real: org.jboss.deployers.spi.DeploymentException: Error deploying solicitacoes-dao-jpa.jar: Exception while processing container metadata for EJB: LocalizadorSetoresDAOBean in unit: solicitacoes-dao-jpa.jar at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:189) [:6.0.0.20100429-M3] at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:59) [:6.0.0.20100429-M3] at org.jboss.deployers.vfs.spi.deployer.AbstractSimpleVFSRealDeployer.deploy(AbstractSimpleVFSRealDeployer.java:56) [:2.2.0.Alpha4] at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62) [:2.2.0.Alpha4] at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:55) [:2.2.0.Alpha4] at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:179) [:2.2.0.Alpha4] at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1857) [:2.2.0.Alpha4] at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1575) [:2.2.0.Alpha4] at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1628) [:2.2.0.Alpha4] at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1516) [:2.2.0.Alpha4] at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:377) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2042) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1081) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1320) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1244) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1137) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:937) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:652) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.deployers.plugins.deployers.DeployersImpl.change(DeployersImpl.java:2008) [:2.2.0.Alpha4] at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:1101) [:2.2.0.Alpha4] at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:679) [:2.2.0.Alpha4] at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117) [:6.0.0.20100429-M3] at org.jboss.system.server.profileservice.repository.ProfileDeployAction.install(ProfileDeployAction.java:70) [:6.0.0.20100429-M3] at org.jboss.system.server.profileservice.repository.AbstractProfileAction.install(AbstractProfileAction.java:53) [:6.0.0.20100429-M3] at org.jboss.system.server.profileservice.repository.AbstractProfileService.install(AbstractProfileService.java:403) [:6.0.0.20100429-M3] at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:377) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2042) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1081) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1320) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1244) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1137) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:892) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:639) [jboss-dependency.jar:2.2.0.Alpha9] at org.jboss.system.server.profileservice.repository.AbstractProfileService.registerProfile(AbstractProfileService.java:308) [:6.0.0.20100429-M3] at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:256) [:6.0.0.20100429-M3] at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:97) [:6.0.0.20100429-M3] at org.jboss.bootstrap.impl.base.server.AbstractServer.startBootstraps(AbstractServer.java:827) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5] at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(AbstractServer.java:417) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5] at java.lang.Thread.run(Thread.java:619) [:1.6.0_20] Caused by: java.lang.Exception: Exception while processing container metadata for EJB: LocalizadorSetoresDAOBean in unit: solicitacoes-dao-jpa.jar at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:551) [:1.3.1] at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:182) [:6.0.0.20100429-M3] ... 38 more Caused by: java.lang.IllegalArgumentException: Container jboss.j2ee:ear=solicitacoes-ear.ear,jar=solicitacoes-dao-jpa.jar,name=LocalizadorSetoresDAOBean,service=EJB3 failed to resolve persistence unit null at org.jboss.injection.PersistenceUnitHandler.addPUDependency(PersistenceUnitHandler.java:135) [:1.3.1] at org.jboss.injection.PersistenceContextHandler.loadXml(PersistenceContextHandler.java:76) [:1.3.1] at org.jboss.ejb3.EJBContainer.processMetadata(EJBContainer.java:629) [:1.3.1] at org.jboss.ejb3.Ejb3Deployment.processEJBContainerMetadata(Ejb3Deployment.java:420) [:1.3.1] at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:529) [:1.3.1] ... 39 more Caused by: java.lang.IllegalArgumentException: Can't find a persistence unit named 'null' in AbstractVFSDeploymentContext@28359170{vfs:///C:/jboss-6.0.0.20100429-M3/server/default/deploy/solicitacoes-ear.ear/solicitacoes-dao-jpa.jar/} at org.jboss.jpa.resolvers.BasePersistenceUnitDependencyResolver.resolvePersistenceUnitSupplier(BasePersistenceUnitDependencyResolver.java:107) [:1.0.2-alpha-1] at org.jboss.ejb3.Ejb3Deployment.resolvePersistenceUnitSupplier(Ejb3Deployment.java:778) [:1.3.1] at org.jboss.ejb3.EJBContainer.resolvePersistenceUnitSupplier(EJBContainer.java:1517) [:1.3.1] at org.jboss.injection.PersistenceUnitHandler.addPUDependency(PersistenceUnitHandler.java:130) [:1.3.1] ... 43 more
Thank you in advance.
Marcos