failed to resolve persistence unit(JBoss 5.1)
crazyit May 16, 2010 3:02 AMI have an application that used to work with WebLogic 10.3.2 well
but it fails starting with JBoss 5.1 GA with the following exception :
org.jboss.deployers.spi.DeploymentException: Error deploying news.ear: Container jboss.j2ee:ear=news.ear,jar=news.ear,name=newsEao,service=EJB3 failed to resol e persistence unit newsUnit at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:201) at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:103) at org.jboss.deployers.vfs.spi.deployer.AbstractVFSRealDeployer.interna Deploy(AbstractVFSRealDeployer.java:45) at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deployAbstractRealDeployer.java:50) at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployeWrapper.java:171) at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployesImpl.java:1439) at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFrst(DeployersImpl.java:1157) at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployerImpl.java:1098) at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstrctControllerContext.java:348) at org.jboss.dependency.plugins.AbstractController.install(AbstractContoller.java:1598) at org.jboss.dependency.plugins.AbstractController.incrementState(AbstrctController.java:934) at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstactController.java:1062) at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstactController.java:984) at org.jboss.dependency.plugins.AbstractController.change(AbstractContrller.java:822) at org.jboss.dependency.plugins.AbstractController.change(AbstractContrller.java:553) at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployerImpl.java:781) at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployrImpl.java:698) at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScnner.java:290) at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScaner.java:221) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:41) at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.jav:317) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTaskaccess$101(ScheduledThreadPoolExecutor.java:98) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTaskrunPeriodic(ScheduledThreadPoolExecutor.java:181) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTaskrun(ScheduledThreadPoolExecutor.java:205) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExeutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecuto.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.IllegalArgumentException: Container jboss.j2ee:ear=news.ear,jar=news.ear,name=newsEao, service=EJB3 failed to resolve persistence unit newsUnit DEPLOYMENTS IN ERROR: Deployment "vfsfile:/D:/jboss-5.0.1.GA/server/default/deploy/news.ear/" is in error due to the following reason(s): java.lang.IllegalArgumentException: Can't find a persistence unit named 'newsUnit' in AbstractVFSDeploymentContext@5205507 {vfsfile:/D:/jboss-5.0.1.GA/server/default/deploy/news.ear/}
My persistence.xml file is in a JAR file bundled in the EAR I try to deploy :
<?xml version="1.0"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="newsUnit" transaction-type="JTA"> <jta-data-source>java:/firstds</jta-data-source> <class>org.crazyit.model.News</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="hibernate.hbm2ddl.auto" value="update"/> </properties> </persistence-unit> </persistence>
I trying to inject the persistence Context into a EJB which in the same EJB-JAR,
@PersistenceContext(unitName="newsUnit") private EntityManager em;
if I deloy the EJB-JAR on JBoss 5.1 , the EJB-JAR works well.
but if I package the EJB-JAR into a application which include a web app, then throw such Exception.