5 Replies Latest reply on Jul 2, 2002 6:04 PM by dsundstrom

    Should findByPrimaryKey follow an ejbLoad() ?

    alice

      The code below is from CD example on JBoss site:

      CD oldCd = home.findByPrimaryKey(id);
      Integer dummy = oldCd.getId();
      // force loading

      CD is an entity bean's remote interface. My question is why we need to "force" ejbLoad by calling a method on the remote interface. When we "find" an entity bean instance, does it call ejbLoad before returning the instance? If not, should we always force this loading?

      Thanks for any answers.

        • 1. Re: Should findByPrimaryKey follow an ejbLoad() ?
          alice

          Will really appreciate if someone can answer. Thanks very much.

          • 2. Re: Should findByPrimaryKey follow an ejbLoad() ?
            albo

            Your ejbFindByPrimaryKey should:
            - SELECT to verify the PK being found exists
            - return the PK

            You should NOT populate your member fields.

            Your ejbLoad will be called when you call a business method.

            - alan

            • 3. Re: Should findByPrimaryKey follow an ejbLoad() ?
              dsundstrom

              It looks like you are using JAWS, and JAWS is not very smart about loading (actually it can't be because of the spec). JBossCMP (CMP 2.0) is a lot smarter about loading, and can be configured to not force a load for this code.

              • 4. Re: Should findByPrimaryKey follow an ejbLoad() ?
                alice

                Hi Dain,

                Do u mean to say that with JBossCMP, we won't need to force the loading and data will be loaded once I find the entity bean? What does the EJB2.0 spec say? Shouldn't entity bean instance be loaded automatically (so we don't have to force ejbLoad) whenever we do a findByPrimaryKey??

                Thanks lot

                • 5. Re: Should findByPrimaryKey follow an ejbLoad() ?
                  dsundstrom

                  > Shouldn't entity bean instance be loaded
                  > automatically (so we don't have to force ejbLoad)
                  > whenever we do a findByPrimaryKey??

                  No, the find just needs make sure that the database has the key. For EJB 2.0 the container is only required to load the data for a field the is required to satisfy a getter. This means that the container can load an entity field by field as requested by a user. On the other end, you can configure the container to load all of the data on-find. Usually somewhere in the middle is best.

                  I suggest you read the Optimized Loading chapter of the JBossCMP documentation.