10 Replies Latest reply on Mar 7, 2006 3:29 AM by Gavin King

    accessing session-beans in Seam

    Andreas Berger Newbie

      Hello,

      I searched the whole day for a sollution and hope you can help me.

      Like in Caveatemtor I got a Seam Component like this:

      @Name("login")
      public class LoginAction {
      
      ...
      
       @In(create = true)
       private UserDAO userDAO;
      ...
      }


      and the UserDAO looks like:

      @Stateless
      public class UserDAOBean extends GenericEJB3DAO<User, Long> implements UserDAO {
      
      ...
      
      }


      There is no Seam import in the UserDAO (as I whish)

      but if I run the application, Seam tells me that he can't find the DAO component

      Caused by: org.jboss.seam.RequiredException: In attribute requires value for component: login.userDAO
       at org.jboss.seam.Component.getInstanceToInject(Component.java:1168)
       at org.jboss.seam.Component.injectFields(Component.java:839)
       at org.jboss.seam.Component.inject(Component.java:669)
      


      If I set the Name in the UserDAO everything works fine

      @Stateless
      @Name("userDAO")
      public class UserDAOBean extends GenericEJB3DAO<User, Long> implements UserDAO {
      
      ...
      
      }


      I also got this in my web.xml

      <context-param>
       <param-name>org.jboss.seam.core.init.jndiPattern</param-name>
       <param-value>appname/#{ejbName}/local</param-value>
       </context-param>


      Is there any possibilty to use the DAO without making it depends on Seam?

      Thank you!
      Andreas

        • 1. Re: accessing session-beans in Seam
          Ido Tamir Newbie

          I would not call myself even a beginner in seam, but Seam uses only annotation for configuration. So at some point you have to use @Name to make the bean available.

          You could of course make another level of subclassing if this is really important:

          @Name("userDAO")
          UserDAOBeanSeam extends UserDAOBean

          hth
          ido

          • 2. Re: accessing session-beans in Seam
            Christian Bauer Master

            Or you could just use EJB injection, which for stateless beans is at call-time:

            @EJB
            UserDAO userDAO;

            • 3. Re: accessing session-beans in Seam
              Andreas Berger Newbie

              Thank you for your fast reply!

              so if I choose to use the (verry cool) @EJB annotation, I have to make my Seam component also an ejb:

              @Name("login")
              @Stateless
              public class LoginAction imlements Login{
              
              ...
              
               //@In(create = true)
               @EJB
               private UserDAO userDAO;
              ...
              }


              I only saw the Caveatemtor example and thought it works as shown there. So I have to think about my architecture again - if I need an addidional Layer or if I want to make my DAOs depends on Seam.

              Thank you guys!
              Andreas

              • 4. Re: accessing session-beans in Seam
                Christian Bauer Master

                There is no public/official Seam CaveatEmptor example. If you got this from CVS, you got something that was under development and not working.

                • 5. Re: accessing session-beans in Seam
                  Jim Hazen Expert

                   


                  if I need an addidional Layer or if I want to make my DAOs depends on Seam.


                  I think Christian's first post was meant to point out that since your DAO is already an EJB3 SSB, that if your Seam component was also an EJB3 bean, you could use the EJB @EJB annotation and use EJB's injection. This means that you don't need to have Seam aware DAOs as long as you have EJB aware Seam components.

                  -Jim

                  • 6. Re: accessing session-beans in Seam
                    Andreas Berger Newbie

                     

                    "christian.bauer@jboss.com" wrote:
                    There is no public/official Seam CaveatEmptor example. If you got this from CVS, you got something that was under development and not working.


                    that's right, I got the current cvs version...

                    @CptnKirk: the reason I want to seperate the Seam from the DAO Layer is that I want to access the DAO also outside of Seam:

                     |--------|
                    |-----| |-----| |EJB3 / |
                    |Seam1| |Seam2| |RMI etc.|
                    |-----| |-----| |--------|
                    
                    |------------------------|
                    | DAO |
                    |------------------------|
                    
                    |------------------------|
                    | Entity PoJo?s |
                    |------------------------|
                    


                    So I've got a "entities.par" and a "dao.ejb3" and 1 ore more Seam webapplications accessing the same DAO (web1.war, web2.war) and maybe other Applications accessing the DAO vs. RMI.

                    I think for this architecture the DAO Layer should not depend on seam...

                    Or are there better sollutions?


                    • 7. Re: accessing session-beans in Seam
                      Jim Hazen Expert

                      Right, I understand that you don't want to change your DAOs. I don't think you have to.

                      It sounds like you already have an EJB3 setup for DAO and business logic. Keep your EJB3 DAOs and simply use the @EJB in your Stateless Session Beans. At this point there is no Seam at all. Then feel free to mix Seam into your various controllers.

                      This will keep Seam out of your DAOs while allowing you to take advantage of both frameworks within your service layer. You should be able to have exactly the architecture you diagram. The only caveat is that Seam1/Seam2 be implemented using EJBs.

                      @EJB is an EJB3 annotation, not Seam.

                      -Jim

                      • 8. Re: accessing session-beans in Seam
                        Andreas Berger Newbie

                        You're right, I'm trying alot to get the right structure for my project and I think DAO's meet my requirements best.

                        btw: I know that @EJB is no Seam annotation, but it's cool anyway ;-)

                        -Andreas

                        • 9. Re: accessing session-beans in Seam
                          Andreas Berger Newbie

                          I mentioned, that I miss all the nice features Seam offers, if I dont use the @Name annotation in my Entities. So I need to wrap each Entity to access it in a JSF like:

                          #{user.firstname}


                          My question is: when I use the Seam annotations in an Entity PoJO, is there an overhead (eg. in performance), if I dont use this Entities via Seam???

                          • 10. Re: accessing session-beans in Seam
                            Gavin King Master

                            No, no overhead at all...