2 Replies Latest reply on Aug 18, 2005 3:06 AM by baumgarten

    EJB SQL query on each entity method

    bingimund

      I have the following code running in a stateless session bean with transactions set to Required. My jbosscmp settings are default.

      BlogUser is a CMP 2 entity bean. I'm running Jboss 4.0.0.

      UserDetails userDetail = new UserDetails();

      try
      {
      BlogUser user = blogUserHome.findByPrimaryKey(userID);
      userDetail.userid = user.getUserID();
      userDetail.pin = user.getPin();
      userDetail.email = user.getEmail();
      }
      catch (FinderException ex)
      {
      //Could not find user
      }

      return userDetail;

      My problem is the follwoing code is generating SQL like this if userID is '12345':

      34 Query SELECT t0_BlogUser.USERID FROM bloguser t0_BlogUser WHERE t0_BlogUser.USERID='12345'
      34 Query SELECT PIN, EMAIL, FIRSTNAME, LASTNAME, SSN, CREATED, SERVICE, COUNTRY, GENDER, ABOUTME, HOBBIES, PETPEVES, PICTURE FROM bloguser WHERE (USERID='12345')
      34 Query SELECT PIN, EMAIL, FIRSTNAME, LASTNAME, SSN, CREATED, SERVICE, COUNTRY, GENDER, ABOUTME, HOBBIES, PETPEVES, PICTURE FROM bloguser WHERE (USERID='12345')
      34 Query SELECT PIN, EMAIL, FIRSTNAME, LASTNAME, SSN, CREATED, SERVICE, COUNTRY, GENDER, ABOUTME, HOBBIES, PETPEVES, PICTURE FROM bloguser WHERE (USERID='12345')


      So there is a single SQL query for each get of an Entity attribute and you can just imagine the scalability issues with this.
      I was under the impression that the first select for the user data would be enough for this transaction and the data would be cached in the entity cache. What am I misunderstanding here....

        • 1. Re: EJB SQL query on each entity method
          lafr

          What's the transaction setting for the entity bean ? It should also be set to Required.
          If it is, then this should not happen.

          Update JBoss to 4.0.2 e.g. to see if it still happens in the latest official release.

          • 2. Re: EJB SQL query on each entity method
            baumgarten

            I use the following in ejb's jbosscmp-jdbc.xml:


            <read-ahead>
            on-find
            <page-size>255</page-size>
            </read-ahead>


            to load all attributes in one SELECT.

            For more information look at chapter "11.7.3. Read-ahead" in the The JBoss 4 Application Server Guide.