0 Replies Latest reply on Nov 26, 2007 11:33 AM by karltraunmueller

    Best Practices for using PersistentContexts in Seam Applicat

      Hello,

      We have a regular Seam 1.2.1.GA Web Application under JBoss 4.0.5.GA with
      - JSF (MyFaces 1.1.4) for the UI,
      - (conversation and session-scoped) Seam Components for UI logic,
      - EJB3 entity beans for persistence,
      - and a POJO-based model for core product logic.

      We've had some bugs related to persistence, mainly due to sloppy use of different kinds of PersistenceContexts scattered all over the place, and incorrectly scoped Seam Components (Conversation, Session).

      The bugs we face are mainly of the form
      - modify an entity in one Page (= View + associated conversation-scoped Seam Component using some PersistenceContext)
      - go to another page (= another View + session-scoped Seam Component using another Persistence Context)
      -> and the changes aren't reflected there (because of the mismatched component scoping).

      So, my questions are now:

      - What kind of PersistenceContext to use? There are three flavors: standard (EJB3), extended (EJB3), and Seam-managed. The standard contexts are applicable in situations where entities are accessed only within the scope of a single EJB method. The extended context is required in lazy-loading scenarios. What about the Seam-managed persistence context? Use it everywhere instead of standard and extended EJB?

      - Are there any best practices of where to put the PersistenceContexts and how many to use? Put a single persistence context in some central DAO-Component? Or is it OK to inject it onto several Seam Components

      - How about the above scenario (conversation-scoped Component's changes should be reflected in session-scoped Component's persistence context)?

      regards,
      Karl Traunmüller