1 Reply Latest reply on Apr 6, 2011 8:14 AM by alesj

    How to guarantee deployment order

    andrey.vorobiev

      Hi, guys.

       

      I have simple J2EE application which consists of following parts:

      1. Hibernate persistence unit.
      2. Singleton bean with post construct method.

       

      In post construct method I lookup EntityManager via JNDI and call some methods on it. The problem is that sometimes during application deployment I get :

      javax.ejb.EJBException: java.lang.RuntimeException: javax.naming.NameNotFoundException: Main-PU not bound
      

       

      As far as I understand it's expected behavior because JBoss doesn't have a way to know that post construct method should be called after persistence unit is bound to JNDI. In normal case I should use:

      @PersistenceContext(name = "Main-PU")
      private EntityManager em;
      

       

      in order to obtain persistence unit. But due to some historical reasons I use JNDI lookup. So my question is: are there any other ways to hint JBoss that post construct method should be called after persistence unit is completely deployed and bound to JNDI.