3 Replies Latest reply on Jun 15, 2009 8:36 PM by gonorrhea

    entityManager getting null intermittently

    devkumar

      We are having a PAGE scoped action class in which entityManager is used via seam injection. There are methods in this action class which are being invoked through ajax calls from the xhtml. We have noticed that sometimes the injected value of entityManager is null for some of the requests. This is not easily reproducible but it does occur. The application code is pretty straightforward (relevant code snippets pasted below)




      UserQueries.java:
      
      @Name("userQueries")
      @Scope(ScopeType.PAGE)
      public class UserQueries
      {
        @Logger
        private Log log;
      
        @In
        private EntityManager entityManager;
      
        List<String> address;
        
        List<String> friends;
        
        public void getAddresses()
        {
          Integer customerId = 9440; //sample id
          User user = entityManager.find(User.class, customerId);
          this.address = user.getAddresses();
        }
      
        public void getFriends()
        {
          Integer customerId = 9440;// sample id
          User user = entityManager.find(User.class, customerId);
          this.friends = user.getFriendList();
        }
        
        .....
        
        .....
        
      }
      
      profile.xhtml:
      
      ........
      ........
                <a4j:form id="profileEditForm">
                     <a4j:region id="getFriendsRegion">
                          <a4j:commandButton id="refreshFriendsBtn" action="#{userQueries.getFriends}"
                               value="Refresh Friends List" reRender="friendsPanel"></a4j:commandButton>
                     </a4j:region>
      
      .........
      .........
      .........
      
                     <a4j:region id="getAddressRegion">
                          <a4j:commandButton id="refreshAddressBtn" action="#{userQueries.getAddresses}"
                               value="Refresh Addresses" reRender="addressPanel"></a4j:commandButton>
                     </a4j:region>
      
      
                     
                </a4j:form>
      
      
      ........
      ........



      Any suggestions? Has anyone faced similar issue?


      We are using seam 2.1.2.CR2 and RichFaces 3.3.1.GA. Any help is highly appreciated.


      Thanks,
      Dev

        • 1. Re: entityManager getting null intermittently
          gonorrhea

          show your components.xml snippet to configure the SMPC, e.g.:


           <persistence:managed-persistence-context name="entityManager"
                                               auto-create="true"
                                persistence-unit-jndi-name="java:/fooEntityManagerFactory"/> 



          Intermittently null sounds very buggy/sketchy to me.  You can't configure the SMPC to be sometimes null when it's injected into a Seam component (before every business method call).


          Plus I would upgrade to 2.1.2.GA if I were you...


          I've never heard of this happening before, and it's a major problem even if it happens just once per session (I've used Seam since 1.2.x).

          • 2. Re: entityManager getting null intermittently
            gonorrhea

            I've been using RF 3.3.1.GA for a month or two now, you can most likely rule those libraries as the root cause.

            • 3. Re: entityManager getting null intermittently
              gonorrhea

              Sorry, I meant rule out