1 Reply Latest reply on Sep 21, 2009 3:53 AM by jaikiran

    5.1 - @PersistenceUnit fails to resolve in Servlet when EJB

    genman

      JBoss AS 5.1

      Servlet code:

      public class Servlet extends HttpServlet {
      
       @PersistenceUnit
       private EntityManagerFactory emf;
      
      


      I created a persistence.xml file and included it a separate EJB .jar file in a .ear file. Things were working fine until I added some EJBs in the persistence.xml containing .jar, and this error started coming up:

      11:34:43,802 ERROR [StandardContext] Context [/mlp] startup failed due to previous errors
      java.lang.IllegalArgumentException: Container org.jboss.web.tomcat.service.TomcatInjectionContainer@1662fdd failed to resolve persistence unit null
       at org.jboss.injection.PersistenceUnitHandler.addPUDependency(PersistenceUnitHandler.java:135)
       at org.jboss.injection.PersistenceUnitHandler.loadXml(PersistenceUnitHandler.java:75)
      


      Is there some reason the persistence unit is "lost" when EJBs are declared within the same .jar file?

        • 1. Re: 5.1 - @PersistenceUnit fails to resolve in Servlet when
          jaikiran

          As per the EJB3 Persistence spec section 6.2.2, the persistence unit if packaged in a ejb .jar is visible only within that jar (unless you use the jarname#unitname convention while injecting the persistence context). However if you package the persistence.xml in the META-INF folder of the .ear then it will be visible to all components in the ear.

          Having said that i don't know why the presence/absence of EJBs in the persistence jar should show a different behaviour (probably the deployment order of the component changes when the EJBs are added?).