4 Replies Latest reply on May 10, 2008 7:50 PM by roman s

    DAO integration problem

    roman s Newbie

      Hey Guys!


      I'm new to seam, and at the moment I'm trying to build a little application, which basically is the same like your hotel booking excample! For now I'm stuck with the search function, since I want to make use of DAO's which isn't the case in your excample.


      I thought I might solve the problem like this:
      (getter/setter aren't included)



      @Stateful
      @Name("Search")
      @Scope(ScopeType.SESSION)
      public class SearchAction implements ISearch {
      
              private String searchstring;
              
              @DataModel
              private List<SearchObject> searchobj;
              
              @In (create = true)
              ISearchDAO db;
              
              public void findSearchObj() {
                      searchobj = db.find( searchstring );
              }
      }




      the implementation of searchDAO looks like



      @Stateless
      @Name("SearchDAO")
      @AutoCreate
      public class SearchDAO implements ISearchDAO {
      
              @PersistenceContext
              EntityManager em;
              
              @Logger
              Log logger;
      
              public List<SearchObject> findSearchObj( String value ) {
                      //some query
              }
      }




      unfortunately this isn't working and the app crashes with
      Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: Search.db


      If I put the query's into the SearchAction obj. it  works fine.


      I don't know what I'm  missing here.. so any help is appreciated!


      Greets


             

        • 1. Re: DAO integration problem
          Fernando Montaño Expert

          Try changing your declaration to:



          @In
          ISearchDAO SearchDAO;
          



          Or:


          @In(value = "#{SearchDAO}")
          ISearchDAO db;
          



          Take into account that the name you use in @Name annotation is the name Seam uses to register the component.

          • 2. Re: DAO integration problem
            roman s Newbie

            Hey!


            First of all thanks for the reply!


            This made the page at least deploy and loadable, but when I now call the find function I get the following exception:


            #{Search.findSearchObj}: /home.xhtml @39,109 action="#{Search.findSearchObj}": javax.ejb.EJBTransactionRolledbackException:
            no concurrent calls on stateful bean 'jboss.j2ee:service=EJB3,name=Search' (EJB3 4.3.13)




            Hm...


            Hope you can help me out again!


            Greets

            • 3. Re: DAO integration problem
              Drew Kutchar Newbie

              Are you using SMPC? If so, then you don't need the EJB3 @PersistenceContext, you can just use @In instead in your DAO.


              Also, the

              (create = true)

              is redundant in you action, since the DAO is marked with @AutoCreate.


              One more thing, it's probably a better idea to inject the EntityManger in your @Stateful action (even if you're not going to use it) to trigger creation of the EntityManager in you Action, rather than somewhere down the line, which will give you more control if you ever want to use different type of FLUSH mode per action.


              cheers,


              Drew

              • 4. Re: DAO integration problem
                roman s Newbie

                Hi again!


                Yes I'm using SMPC and so you where right with the @In annotation.


                It now works, but there was one other problem:


                my EntityManager variable 'em' needed to have the same name as declared in components.xml (where it was declared as 'entityManager')... so I changed the name of the variable, and now its works nicely.


                Thanks for your help!