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

    EJB SQL query on each entity method

    Bjorn Ingimundarson Newbie

      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....