2 Replies Latest reply on Oct 1, 2008 10:59 AM by mrossix

    run EntityQuery outside seam context

    mrossix

      Hi,
      it's possible to run the seam daos outside the seam context?


      I try to create a new java project, and import the EntityQuery and EntityHome created with seam-gen (with all the required library), but it doesn't work.


      Here the message ...


      java.lang.IllegalStateException: No application context active

        • 1. Re: run EntityQuery outside seam context
          gjeudy

          I think you got your answer. If you try to use a Seam component outside it's context it will not work because dependencies are not injected in the component, transaction is not started etc...


          The assumption is that a Seam application context should be active in this case.

          • 2. Re: run EntityQuery outside seam context
            mrossix
            The dependencies can be injected "by hand". If i create my custom dao i can resuse it in other "non seam" project. For example:

            @Name("personDAO")
            @Scope(ScopeType.CONVERSATION)
            public class PersonDAO {
                 
                @In EntityManager em;

                public List<Person> loadPersons()
                {
                     return em.createQuery("select p from Person p").getResultList();
                }

            .....
            ...
            }


            To use it outside seam:

            PersonDAO personDAO = new PersonDAO ();          
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("helloworld12");
            EntityManager em = emf.createEntityManager();     

                      
            // manual injection
            personDAO .setEm(em);          

            personDAO .loadPersons();



            Obviously i loose the seam feature (like conversation in this case), but i can reutilize the same dao, e.g. for a batch precess.
            But this approach doesn't work with the daos generated by seam application framework.