8 Replies Latest reply on Aug 17, 2004 12:26 PM by hmartin

    Exception + Bugfix(?): could not load field value with comm

    hmartin

      Hello,

      we have developed a J2EE Application (5 SLSB's, 25 EB) which is running with JBOSS 3.2.5 and JDK 1.4.2_04 under a Windows environment. We are using CMP 2.x with CMR. The Database is Oracle 9i. Our EJB-Container uses commit option A (not clustered).

      With this configuration we get sometimes (!) but not allways the Exception
      could not load field value ... when we traverse the entities in a relationship and try to access the fields of one entity from the collection.

      I know that there was a bug like this in version 3.2.4 but this should be already fixed (jboss-Bugs-978763).

      After fixing the code everything works fine. Can please someone look at the fix if i am right or if i have only too less sleep.

      Fixed file: jboss-3.2.5src\server\src\main\org\jboss\ejb\plugins\cmp\jdbc\JDBCCMP2xFieldBridge.java

      Mehod: getInstanceValue

      Original

      public Object getInstanceValue(EntityEnterpriseContext ctx)
       {
       // notify optimistic lock
       FieldState fieldState = getFieldState(ctx);
       if(!fieldState.isLoaded())
       {
       manager.loadField(this, ctx);
       if(!fieldState.isLoaded())
       throw new EJBException("Could not load field value: " + getFieldName());
       }
      
       return fieldState.getValue();
       }




      Patch:

      public Object getInstanceValue(EntityEnterpriseContext ctx)
       {
       // notify optimistic lock
       FieldState fieldState = getFieldState(ctx);
       if(!fieldState.isLoaded())
       {
       manager.loadField(this, ctx);
      
       if(!fieldState.isLoaded()) {
       fieldState = getFieldState(ctx);
       if(!fieldState.isLoaded()) {
       throw new EJBException("Could not load field value: " + getFieldName());
       }
       }
       }
      
       return fieldState.getValue();
       }



      Description:

      In the method above you make
      FieldState fieldState = getFieldState(ctx);
      . The method getFieldState creates, if the condition is true a new Object FieldState. Later comes the call
      manager.loadField(this, ctx);
      . This method bind the cache to the context and looks if the field is already loaded. If not it loads the field from the database. The problem seems to be the check in the loadField method because this method call getFieldState implicitly again and also possible creates a new (!) FieldState instance to test if the field is loaded. After
      manager.loadField(this, ctx);
      there is a call
      if(!fieldState.isLoaded()) { ...
      but here to the possible other old instance from FieldState. So it can be that the value is loaded but an Exception will be thrown.

        • 1. Re:  Exception + Bugfix(?): could not load field value with
          aloubyansky

          It can happen when two threads invoke getFieldState() at the same time and get different instances. Do you mark method/beans as read-only and reentrant?

          • 2. Re:  Exception + Bugfix(?): could not load field value with
            hmartin

            Hello,

            thank you for your reply. It is true what you thinking. Our beans are marked reentrant and the getXXX-Methods are read only.

            • 3. Re:  Exception + Bugfix(?): could not load field value with
              aloubyansky

              And you should be running NotSupported, right?
              The patch you suggest does not solve the big problem.
              This is fixed in 3.2.6RC2.
              Thanks.

              • 4. Re:  Exception + Bugfix(?): could not load field value with
                hmartin

                Hello Alex,

                sorry for my late reply.

                The method from our bean where we have the touble uses RequiresNew and not NotSupported for the transaction type. Does your fix address this transaction type too ?

                • 5. Re:  Exception + Bugfix(?): could not load field value with
                  aloubyansky

                  What container configuration and locking policy are you using?
                  My fix just locks the instance for the duration of the invocation. Which makes sense only for the Standard container configuration.
                  Earlier this couldn't happen if the locking policy is NoLock (which should not be used with Standard container), if tx is NotSupported and the container is reentrant.

                  • 6. Re:  Exception + Bugfix(?): could not load field value with
                    hmartin

                    Hello Alex,

                    we are using the Standard container configuration with modifications (e.g. commit option A)

                    <container-configuration>
                     <container-name>Standard CMP 2.x EntityBean</container-name>
                     <call-logging>false</call-logging>
                     <invoker-proxy-binding-name>entity-rmi-invoker</invoker-proxy-binding-name>
                     <sync-on-commit-only>false</sync-on-commit-only>
                     <insert-after-ejb-post-create>false</insert-after-ejb-post-create>
                     <container-interceptors>
                     <interceptor>org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor</interceptor>
                     <interceptor>org.jboss.ejb.plugins.LogInterceptor</interceptor>
                     <interceptor>org.jboss.ejb.plugins.SecurityInterceptor</interceptor>
                     <interceptor>org.jboss.ejb.plugins.TxInterceptorCMT</interceptor>
                     <interceptor metricsEnabled="true">org.jboss.ejb.plugins.MetricsInterceptor</interceptor>
                     <interceptor>org.jboss.ejb.plugins.EntityCreationInterceptor</interceptor>
                     <interceptor>org.jboss.ejb.plugins.EntityLockInterceptor</interceptor>
                     <interceptor>org.jboss.ejb.plugins.EntityInstanceInterceptor</interceptor>
                     <interceptor>org.jboss.ejb.plugins.EntityReentranceInterceptor</interceptor>
                     <interceptor>org.jboss.resource.connectionmanager.CachedConnectionInterceptor</interceptor>
                     <interceptor>org.jboss.ejb.plugins.EntitySynchronizationInterceptor</interceptor>
                     <interceptor>org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor</interceptor>
                     </container-interceptors>
                     <instance-pool>org.jboss.ejb.plugins.EntityInstancePool</instance-pool>
                     <instance-cache>org.jboss.ejb.plugins.InvalidableEntityInstanceCache</instance-cache>
                     <persistence-manager>org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager</persistence-manager>
                     <locking-policy>org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock</locking-policy>
                     <container-cache-conf>
                     <cache-policy>org.jboss.ejb.plugins.LRUEnterpriseContextCachePolicy</cache-policy>
                     <cache-policy-conf>
                     <min-capacity>50</min-capacity>
                     <max-capacity>1000000</max-capacity>
                     <overager-period>300</overager-period>
                     <max-bean-age>600</max-bean-age>
                     <resizer-period>400</resizer-period>
                     <max-cache-miss-period>60</max-cache-miss-period>
                     <min-cache-miss-period>1</min-cache-miss-period>
                     <cache-load-factor>0.75</cache-load-factor>
                     </cache-policy-conf>
                     </container-cache-conf>
                     <container-pool-conf>
                     <MaximumSize>200</MaximumSize>
                     </container-pool-conf>
                     <commit-option>A</commit-option>
                     </container-configuration>


                    • 7. Re:  Exception + Bugfix(?): could not load field value with
                      aloubyansky

                      Ok thanks, I think it is fixed.

                      • 8. Re:  Exception + Bugfix(?): could not load field value with
                        hmartin

                        Thank you too for your help.