1 Reply Latest reply on Sep 6, 2007 10:47 AM by christian.bauer

    Pb Initializing database on app startup with postInitializat

    zdaler

      I launch a method on application startup using the org.jboss.seam.postInitialization event. It work fine except if I access the database (and I need to) :

      using seam managed entity manager :

      @In
       private EntityManager em;
      
      @Observer("org.jboss.seam.postInitialization")
      private void setupAFewThings() throws ComentSystemException {
       MyObject w = new MyObject() ;
       w.setName("test_name") ;
       em.getTransaction().begin();
       em.persist(w) ;
       em.getTransaction().commit();
      }


      or manually creating a new entity manager like this :

      @Observer("org.jboss.seam.postInitialization")
      private void setupAFewThings() throws ComentSystemException {
       MyObject w = new MyObject() ;
       w.setName("test_name") ;
       EntityManagerFactory emf = Persistence.createEntityManagerFactory("myDatabase");
       EntityManager em = emf.createEntityManager();
       em.getTransaction().begin();
       em.persist(w) ;
       em.getTransaction().commit();
      }


      I get the same error ("java.lang.IllegalStateException: JTA EntityManager cannot access a transactions") :
      16:26:18,530 ERROR [[/coment_demo]] Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.jboss.seam.servlet.SeamListener
      java.lang.IllegalStateException: JTA EntityManager cannot access a transactions
      at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:316)
      at com.sopinspace.coment.core.WorkflowManager.addDefaultWorkflow(WorkflowManager.java:53)
      at com.sopinspace.coment.core.WorkflowManager.create(WorkflowManager.java:62)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
      at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)


      Any help ?