4 Replies Latest reply on Mar 9, 2007 3:08 PM by cja987

    Using EntityHome with multiple Entities

    sontiver

      Greetings,

      I've been using the EntityHome from the Seam Framework, but have stumbled upon the issue of having to deal with two unrelated entities simultaneously in the same CRUD actions. Almost like if we could use EntityHome<E1,E2>

      Initial thoughts were to wrap the two Entity Beans under one Pojo (not an Entity), and pass that to EntityHome, would that be an approach to follow? is there another way of reusing CRUD functionality from the EntityHome and apply it to multiple entities?
      I'm comfortable extending the Framework, any pointers in that direction could be helpful as well.

      Thanks

      Sergio Ontiveros

        • 1. Re: Using EntityHome with multiple Entities

          If they really are unrelated, why not just use two EntityHome instances? If they are actually related somehow, you can express the relation in JPA/Hibernate terms as @OneToOne (or whatever your relation is) and get at one object through the other -- no entityhome required.

          @EntityHome seems to exist largely for the purpose of exposing entities as components without making the entities themselves components. It's also a great place to do bijection that concerns entities (since even if you do use the antipattern of entities-as-components, they don't intercept). If you need to deal with a list of objects, you could always wrap a @DataModel with your own controller.

          • 2. Re: Using EntityHome with multiple Entities
            pmuir

            Use another seam bean (a controller) which has a the CRUD methods, inject in the home objects, and call the relevant methods.

            • 3. Re: Using EntityHome with multiple Entities
              sontiver

              Hello,

              Thanks for you quick reply, these are related in the sense that are being created/updated in the same page and a single SFSB currently supports the page.
              Ideally we want to reuse the EntityHome (if somehow we get to handle 2 entities).

              If we had two EntityHome for the same page we may need to synchronize the crud actions for both?


              Thanks,

              Sergio Ontiveros

              • 4. Re: Using EntityHome with multiple Entities

                Both EntityHome instances should use the same conversation-scoped EntityManager (a component named "entityManager" by default), so they'll guaranteed participate in the same JTA transaction. No need to do any extra "synchronizing".