5 Replies Latest reply on Mar 7, 2011 4:58 AM by Ederson.Savi

    Error occurred saving the cache

    benpage1

      I'm creating an AIR application using the Model Driven Development tools and hoping to make use of the offline cache. The generated value objects and services are working well when connected but I have been unable to get the cache working.

       

      Currently I am generating custom offline adaptors for each of my Model entities and assigning them to the offlineAdapter property of each data service as follows:

       

        _terminalService.serviceControl.autoCommit=false;
        _terminalService.serviceControl.autoConnect=true;
        _terminalService.serviceControl.fallBackToLocalFill=true;
        _terminalService.serviceControl.autoSaveCache=true;
        _terminalService.serviceControl.autoMerge=true;
        _terminalService.serviceControl.autoSyncEnabled=true;
        _terminalService.serviceControl.encryptLocalCache=false;
        _terminalService.serviceControl.offlineAdapter=new TerminalOfflineAdapter();
        _terminalService.serviceControl.cacheID="ss-sclient-39";
      
      

      When I run my application it works as anticipated but I am seeing the following error in the console log:

       

      7/27/2010 12:21:25.677 [DEBUG] mx.data.DataStore Saving cached query: store id: ["getByMacAddress","001CC4313675"] lastWritten: Tue Jul 27 12:21:25 GMT+0100 2010 lastAccessed: Tue Jul 27 12:21:25 GMT+0100 2010 created: Tue Jul 27 12:21:25 GMT+0100 2010 metadata: (null) type: 1 referenced ids: ["common.Terminal:#:13"]
      7/27/2010 12:21:25.677 [DEBUG] mx.data.LSODataStore dbStore lock released: 965366152
      7/27/2010 12:21:25.677 [ERROR] mx.data.DataStore Error occurred saving the cache: TypeError: Error #1009: Cannot access a property or method of a null object reference. stack: TypeError: Error #1009: Cannot access a property or method of a null object reference.
           at mx.data.offline::EntityManager/save()[C:\depot\DataServices\trunk\frameworks\projects\airfds\src\mx\data\offline\EntityManager.as:104]
           at mx.data.offline::EntityManager/update()[C:\depot\DataServices\trunk\frameworks\projects\airfds\src\mx\data\offline\EntityManager.as:345]
           at mx.data::SQLiteOfflineAdapter/updateOfflineItems()[C:\depot\DataServices\trunk\frameworks\projects\airfds\src\mx\data\SQLiteOfflineAdapter.as:120]
           at mx.data::DataStore/persistCacheItems()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:4543]
           at mx.data::DataStore/persistDataService()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:4679]
           at mx.data::DataStore/doSaveCache()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:3755]
           at Function/()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:3711]
           at mx.data::DataStore/http://www.adobe.com/2006/flex/mx/internal::saveCache()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:3727]
           at mx.data::DataList/http://www.adobe.com/2006/flex/mx/internal::processSequenceResult()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataList.as:3063]
           at mx.data::DataListRequestResponder/result()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataListRequestResponder.as:103]
           at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84]
           at NetConnectionMessageResponder/resultHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:547]
      

       

      If I then disconnect from the server and attempt to run my client again I get the following error:

       

      7/27/2010 12:27:46.548 [DEBUG] mx.data.DataService.common.Terminal DataService.fill() called for destination: common.Terminal with args: ["getByMacAddress","001CC4313675"] includesProperties: (include default - excludes: [])
      7/27/2010 12:27:46.548 [INFO] mx.messaging.Producer 'ds-producer-common.Terminal' producer sending message 'EF832901-F3A4-7AE3-EF12-13A8897408CC'
      TypeError: Error #1009: Cannot access a property or method of a null object reference.
           at mx.data.offline::EntityManager/executeSelectQuery()[C:\depot\DataServices\trunk\frameworks\projects\airfds\src\mx\data\offline\EntityManager.as:446]
           at mx.data.offline::EntityManager/executeQuery()[C:\depot\DataServices\trunk\frameworks\projects\airfds\src\mx\data\offline\EntityManager.as:432]
           at mx.data::SQLiteOfflineAdapter/internalExecuteOfflineQuery()[C:\depot\DataServices\trunk\frameworks\projects\airfds\src\mx\data\SQLiteOfflineAdapter.as:318]
           at mx.data::SQLiteOfflineAdapter/executeOfflineQuery()[C:\depot\DataServices\trunk\frameworks\projects\airfds\src\mx\data\SQLiteOfflineAdapter.as:202]
           at Function/()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:1651]
           at mx.data::DataStore/http://www.adobe.com/2006/flex/mx/internal::fill()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:1765]
           at mx.data::ConcreteDataService/internalFill()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\ConcreteDataService.as:7235]
           at Function/()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\ConcreteDataService.as:1317]
           at mx.data::ConcreteDataService/fill()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\ConcreteDataService.as:1336]
           at mx.data::DataManager/fill()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataManager.as:1560]
           at _Super_TerminalService/getByMacAddress()[C:\Documents and Settings\benp.NB\My Documents\src\qms\workspace\CommonClient\src\common\model\_Super_TerminalService.as:226]
           at airclient.application::AirClientImpl/initialiseTerminalDetails()[C:\Documents and Settings\benp.NB\My Documents\src\qms\workspace\AirClient\src\airclient\application\AirClientImpl.as:146]
           at Function/()[C:\Documents and Settings\benp.NB\My Documents\src\qms\workspace\AirClient\src\airclient\application\AirClientImpl.as:268]
           at mx.collections::ItemResponder/result()[E:\dev\4.x\frameworks\projects\framework\src\mx\collections\ItemResponder.as:129]
           at mx.rpc::AsyncToken/http://www.adobe.com/2006/flex/mx/internal::applyResult()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AsyncToken.as:239]
           at mx.rpc.events::ResultEvent/http://www.adobe.com/2006/flex/mx/internal::callTokenResponders()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\events\ResultEvent.as:207]
           at mx.data::ConcreteDataService/http://www.adobe.com/2006/flex/mx/internal::dispatchResultEvent()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\ConcreteDataService.as:3427]
           at Function/http://adobe.com/AS3/2006/builtin::apply()
           at mx.rpc::AsyncDispatcher/timerEventHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AsyncDispatcher.as:50]
           at flash.utils::Timer/_timerDispatch()
           at flash.utils::Timer/tick()
      
      

       

      I'm slightly confused by the fact that the offline adaptors are derived from SQLiteOfflineAdapter and are being run within an AIR application but I am still seeing references to the LSODataStore in the logs (which I thought was only used for Flash applications). Also if I attempt to set encryptLocalCache to true I get the following error:

       

      7/27/2010 12:32:10.409 [DEBUG] mx.data.DataStore Adding data service: common.Terminal to the data store: my-rtmp:true initialized: false
      Error: Encryption is not supported for local shared objects.
           at mx.data::LSODatabase/set encryptLocalCache()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\LSODatabase.as:149]
           at mx.data::DataStore/set encryptLocalCache()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:391]
           at mx.data::ConcreteDataService/set encryptLocalCache()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\ConcreteDataService.as:227]
           at mx.data::DataManager/set encryptLocalCache()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataManager.as:392]
           at airclient.application::AirServiceFactory/configureService()[C:\Documents and Settings\benp.NB\My Documents\src\qms\workspace\AirClient\src\airclient\application\AirServiceFactory.as:236]
      

       

      Does anyone know what's going on here?

       

      Thanks!

        • 1. Re: Error occurred saving the cache
          tomj Adobe Employee

          Please be sure that you are linking your AIR application with airfds.swc and not playerfds.swc.  This is how the library knows to use SQLite for offline storage and would be the reason why it is trying to use the LSO for storage.

          1 person found this helpful
          • 2. Re: Error occurred saving the cache
            Mike Peterson Level 1

            If you are working in Flash Builder 4.x and you select "Desktop" as your Flex application type, your app should automatically get the linking to airfds.swc that Tom mentions in his response. Is it possible you set the app type or "Web"? If not, maybe there is some other issue with the Flex build path.

            • 3. Re: Error occurred saving the cache
              benpage1 Level 1

              Ah, thanks! That certainly solves the LSO issue - I've changed to linking with airfds.swc and I'm now seeing lots of healthy looking SQLDBCache output in the logs when I run the application with a connection. Unfortunately if I then stop the server and run the application again I'm still seeing a problem. The app does load some data from the cache (I have several services) but then stops with the following error before it can load everything:

               

              7/27/2010 15:43:46.929 [DEBUG] mx.data.SQLDBCache SQLDBCache - getCollection(_common.Customer_ic) creating new collection
              7/27/2010 15:43:46.929 [DEBUG] mx.data.SQLDBCache SQLDBCache - before load data - create table if not exists: CREATE TABLE IF NOT EXISTS [_common_Customer_ic] (id VARCHAR PRIMARY KEY, data BLOB);
              7/27/2010 15:43:46.960 [DEBUG] mx.data.SQLDBCache SQLDBCache - after load data - create table if not exists
              7/27/2010 15:43:46.960 [DEBUG] mx.data.SQLDBCache SQLDBCache - before select: SELECT id,data FROM [_common_Customer_ic]
              TypeError: Error #1009: Cannot access a property or method of a null object reference.
                   at mx.data::DataStore/restoreReferencedIds()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:4766]
                   at mx.data::DataStore/restoreReferencedItems()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:4736]
                   at mx.data::DataStore/restoreAssociations()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:4880]
                   at mx.data::DataStore/restoreReferencedItems()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:4759]
                   at Function/()[C:\depot\DataServices\trunk\frameworks\projects\data\src\mx\data\DataStore.as:1742]
                   at mx.rpc::Responder/result()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\Responder.as:56]
                   at mx.rpc::AsyncToken/http://www.adobe.com/2006/flex/mx/internal::applyResult()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AsyncToken.as:239]
                   at mx.rpc.events::ResultEvent/http://www.adobe.com/2006/flex/mx/internal::callTokenResponders()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\events\ResultEvent.as:207]
                   at Function/http://adobe.com/AS3/2006/builtin::apply()
                   at mx.rpc::AsyncDispatcher/timerEventHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AsyncDispatcher.as:50]
                   at flash.utils::Timer/_timerDispatch()
                   at flash.utils::Timer/tick()
              

               

              In both connected and disconnected operation there is no user input, so the sequence of queries should be identical. Each service I use is configured identically except that they each use their own automatically-generated OfflineAdaptor. Any suggestions?

               

              Many thanks

              • 4. Re: Error occurred saving the cache
                Mike Peterson Level 1

                I'm currently looking into this issue.

                • 5. Re: Error occurred saving the cache
                  Ederson.Savi

                  I'm in the same situation, it was possible to correct the problem or make a workaround?