Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-5049

NoInitialContextException on deployment of EAR that contains MDB and persistence.xml

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: JBossAS-4.2.2.GA
    • Component/s: EJB
    • Labels:
      None
    • Environment:
      Windows XP SP2, JDK1.5.0_09, JBoss AS-4.2.2.GA, SEAM 2.0.0.GA
    • Similar Issues:
      Show 10 results 

      Description

      When deploy an EAR that contains EJB3 MDB, you may receive NoInitialContextException on the deployment of other EJB3 elements. In my particular case, I have a persistence.xml file that configures the EntityManager. The deployment of this persistence.xml throws the NoInitialContextException. Depending on the contents of the EAR, it may be other deployment unit that is throwing this exception.

      Tracing into the deployment code shows that the problem is with the latest code change in the org.jboss.ejb3.EJBContainer class. This class has method named getInitialContext(). In the previous release it returns a newly constructed InitialConext object. In the 4.2.2.GA, it returns the shared static InitialContext object from the InitialContextFactory class. The MDB deployer class org.jboss.ejb3.mdb.MessagingContainer.getJMSProviderAdapter() method calls this method to obtain a InitialContext object and closes this InitialContext object after using it. This results in that the shared InitialContext object been closed prematurely as it is used later on to deploy other EJB3 units, such as the persistence.xml file in my case.

      Suggested fix:
      Change the org.jboss.ejb3.mdb.MessagingContainer.getJMSProviderAdapter() method as follows:
      Change the line (around line # 586):
      Context context = getInitialContext();
      to:
      Context context = initialContextProperties == null ? new InitialContext() : new InitialContext(initialContextProperties);

      The above suggested change is copied from the previous implementation of the EJBContainer.getInitialContext() method.

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            benchato Benoit de CHATEAUVIEUX added a comment -

            As a workaround, I changed the name of the jar archive that contains my EJB3 MDB in order to load other jar/war first.

            Show
            benchato Benoit de CHATEAUVIEUX added a comment - As a workaround, I changed the name of the jar archive that contains my EJB3 MDB in order to load other jar/war first.
            Hide
            benchato Benoit de CHATEAUVIEUX added a comment -

            But there is a much more elegant workaround in the forum:
            http://www.jboss.com/index.html?module=bb&op=viewtopic&t=123997&postdays=0&postorder=asc&start=10
            (thanks to alllle)

            Show
            benchato Benoit de CHATEAUVIEUX added a comment - But there is a much more elegant workaround in the forum: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=123997&postdays=0&postorder=asc&start=10 (thanks to alllle)

              People

              • Assignee:
                wolfc Carlo de Wolf
                Reporter:
                alllle Alan Feng
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Development