4 Replies Latest reply on Dec 4, 2009 10:15 AM by Krzysztof Kraska

    EntityManager - IllegalStateException: No application context active

    Krzysztof Kraska Newbie
      In the code below:

      @Name("startupThread")
      @Scope( ScopeType.APPLICATION )
      @Startup
      public class StartupThread extends Thread
      {
              private Thread t;
             
              @In
              EntityManager entityManager;
             
              @Create
              public void init( )
              {
                      List<X> xs = entityManager.createQuery( "select x from X x" ).getResultList( );
                      t = new StartupThread( );
                      t.start( );
              }
             
              public void run( )
              {
                      while( true )
                      {
      (*)                     EntityManager em = (EntityManager)Component.getInstance( "entityManager" );
                              List<X> xs = entityManager.createQuery( "select x from X x" ).getResultList( );
                             
                              try { Thread.sleep( 3000L ); }  catch( Exception ex ) { }
                      }
              }
      }

      there is an exception:
      Exception in thread "Thread-20"
      java.lang.IllegalStateException: No application context active
           at org.jboss.seam.Component.forName(Component.java:1945)
           at org.jboss.seam.Component.getInstance(Component.java:2005)
           at org.jboss.seam.Component.getInstance(Component.java:1983)
           at org.jboss.seam.Component.getInstance(Component.java:1977)
           at org.jboss.seam.Component.getInstance(Component.java:1972)
           at org.domain.jakis.session.StartupThread.run(StartupThread.java:51)

      throwed from the line:
           EntityManager em = (EntityManager)Component.getInstance( "entityManager" );

      What is a reason of the exception? I'am a newbe and I need your help.