6 Replies Latest reply on Oct 8, 2007 5:16 AM by marius.oancea

    Seam @In EntityManager vs. Extended Persistence context.

    marius.oancea

      I;ve build a tree using richfaces and seam. The tree model is saved into a session stateful component.

      @Stateful
      @Scope(SESSION)
      @Name("leftTreeBean")


      I used Extended Persisence Context and all works but it seems that that exteded persistence context does not propagate into DAO objects (Stateless session beans).

      If I switch to seam managed persistence tree does not work (i supose because seam managed persistend only work inside conversation - and this cannot be the case because the tree is displayed all the time).

      How can I make the dao called from "leftTreeBean" use the same EntityManager?

        • 1. Re: Seam @In EntityManager vs. Extended Persistence context.
          matt.drees

           

          "marius.oancea" wrote:
          If I switch to seam managed persistence tree does not work


          What, precisely, breaks?

          (There should be no problem injecting a SMPC into a session-scoped component)

          • 2. Re: Seam @In EntityManager vs. Extended Persistence context.
            matt.drees

             

            "matt.drees" wrote:
            There should be no problem injecting a SMPC into a session-scoped component


            That is, if the conversation context is active. (eg, not during RestoreView).

            • 3. Re: Seam @In EntityManager vs. Extended Persistence context.
              pmuir

              Matt, the problem is that the SMPC is not session scoped,so therefore stuff loaded by the SMPC becomes unmanaged inside that bean (I guess this is the problem, it normally is).

              • 4. Re: Seam @In EntityManager vs. Extended Persistence context.
                pmuir

                There are a number of techniques discussed on the forum a few times for dealing with this.

                • 5. Re: Seam @In EntityManager vs. Extended Persistence context.
                  thejavafreak

                   

                  "marius.oancea" wrote:
                  I;ve build a tree using richfaces and seam. The tree model is saved into a session stateful component.

                  @Stateful
                  @Scope(SESSION)
                  @Name("leftTreeBean")


                  I used Extended Persisence Context and all works but it seems that that exteded persistence context does not propagate into DAO objects (Stateless session beans).

                  If I switch to seam managed persistence tree does not work (i supose because seam managed persistend only work inside conversation - and this cannot be the case because the tree is displayed all the time).

                  How can I make the dao called from "leftTreeBean" use the same EntityManager?


                  I made the SMPC into a conversation scoped and it works. But I don't know in your case.

                  • 6. Re: Seam @In EntityManager vs. Extended Persistence context.
                    marius.oancea

                    Just for clarification some of my requirements:

                    - Session scoped "leftTreeBean" (because conversation is too short)
                    - "leftTreebean" provides a getRoot method that creates a new TreeNodeimpl and makes db query to populate first level of the tree. Tree nodes are a custom class ClazzTreeNode.

                    ClazzTreeNode is not a seam component. Just a java object. Its "getChildren" makes a database call to a dao to find out the children of a specific node.

                    I would like to push the code to findChildrens, findFirstLevel and so on into another classes (DAO) to be able to reuse them.

                    Note:

                    During working with the application tree can be modified.
                    Tree is huge (about 2.5 million nodes) so it cannot be loaded in memory.
                    I expect DAO-s to be stateless session beans


                    I use richfaces with ajax switch type.

                    Any critics to this design ?