1 Reply Latest reply on Jan 15, 2008 12:31 AM by ruettimac

    DAO's: stateless or not

      looking for opinions/experience with DAO's in Seam...

      Our application has complex query logic that we want to share between a stateful website and a restful API. For this reason we will be creating a set of DAO's. I would also like to take advantage of the seam managed persistence context for the stateful website.

      The logical choice seems to be to implement the DAO's as stateless session beans triggered by stateful actions (for the website) and the API. I believe I can use Seam to inject the EntityManager.

      A couple of questions:
      1. can the seam injection be overriden? i.e. if I wanted to provide my own EntityManager when called by the API
      2. is there any advantage/disadvantage in making the DAO's stateful? - potentially this might help with question 1...

      Thanks
      Duncan

        • 1. Re: DAO's: stateless or not
          ruettimac

          Hi,

          I am thinking about the same question - should I or should I not. The main problem is, that I have implemented certain queries (load the current user from the database for example) the second time in my action beans and it is time for a refactoring.

          You have two options in my opinion:

          Since seam is a component framework, you can also inject another component (action in example terms) into another component. So I have an action coping with customers which implements the query to load a certain user. Another component needs the user to load the computers of the user (toMany relationship). So I can inject the user action into the computer action.

          Second option is to create a DAO. Since EJB3 is more object oriented than the previous specifications, I do not like to add a DAO-Layer. In my opinion, it has to be more simple - queries and persistence functions should also be in the entity bean, so I have all logic in the entity bean or my business object. The entity bean is now as intelligent as it should be; It can load itself, can query for itself and can operate on itself (business specific).


          An interesting question is, how seam will handle the different scope definitions if you inject components into other components. For example, if you inject (@In) a component with scope EVENT into a component with Scope CONVERSATION.

          Regards,

          Cyrill