Cayenne
  1. Cayenne
  2. CAY-1432

java.io.NotSerializableException when using OSCache for query cache with prefetches and persitent cache.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.0
    • Fix Version/s: 3.0.2, 3.1M3
    • Component/s: Core Library
    • Labels:
    • Environment:
      SQL Server 2008 10.0.2531.0, OSCache 2.4, jTDS Driver 1.2.4, Kernel: 2.6.31-20-generic

      Description

      When using persistent OSCache with prefetching like:

      SelectQuery q = proto.queryWithParameters(params);
      q.addPrefetch(RichProduct.MANUFACTURER_PROPERTY);
      q.addPrefetch(RichProduct.RAW_PRODUCT_PROPERTY);
      q.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
      q.setCacheGroups("products");

      Upon execution of this query the following exception occurs:

      ERROR com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache
      [oscache] Exception persisting RichProduct/subCategory =
      <ObjectId:SubCategory, category_id=1,
      id=1>/categoryName/subCategoryName/cost
      com.opensymphony.oscache.base.persistence.CachePersistenceException:
      Unable to write
      '/tmp/cache/application/0/0/5/005126BC80FABAA4C582919EDF0B9304.cache'
      in the cache. Exception: java.io.NotSerializableException, Message:
      org.apache.cayenne.access.ListWithPrefetches
      at com.opensymphony.oscache.plugins.diskpersistence.AbstractDiskPersistenceListener.store(AbstractDiskPersistenceListener.java:376)
      at com.opensymphony.oscache.plugins.diskpersistence.AbstractDiskPersistenceListener.store(AbstractDiskPersistenceListener.java:238)

      <rest of stack trace removed>

      If the prefetches are removed the issue does not occur.

      If the in memory cache is used the issue does not occur either.

      1. cay-1432.patch
        5 kB
        Dzmitry Kazimirchyk

        Activity

        aadamchik committed 1090122 (1 file)
        Reviews: none

        CAY-1432 java.io.NotSerializableException when using OSCache for query cache with prefetches and persitent cache.

        oops...

        Andrus Adamchik made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Fix Version/s 3.0.2 [ 12315325 ]
        Fix Version/s 3.1M3 [ 12316228 ]
        Resolution Fixed [ 1 ]
        Hide
        Andrus Adamchik added a comment -

        I applied the patch.

        Note on possible improvement of the unit test. To guarantee correct serialization behavior, it is best to check the entire tree of objects. E.g. in the future ListWithPrefetches may wrap another list that is not serializable. So I would recommend doing actual serialization with Util.cloneViaSerialization. This will catch possible future issues with the underlying data structures.

        BTW, even with this fix, there's no guarantee that serialized cache will deserialize properly. In this case we are dealing with SHARED_CACHE that will probably work. LOCAL_CACHE may require some environment magic to be attached back to the right DataContext. I guess we'll leave this aspect out of this Jira. So just mentioning...

        Show
        Andrus Adamchik added a comment - I applied the patch. Note on possible improvement of the unit test. To guarantee correct serialization behavior, it is best to check the entire tree of objects. E.g. in the future ListWithPrefetches may wrap another list that is not serializable. So I would recommend doing actual serialization with Util.cloneViaSerialization. This will catch possible future issues with the underlying data structures. BTW, even with this fix, there's no guarantee that serialized cache will deserialize properly. In this case we are dealing with SHARED_CACHE that will probably work. LOCAL_CACHE may require some environment magic to be attached back to the right DataContext. I guess we'll leave this aspect out of this Jira. So just mentioning...
        aadamchik committed 1090120 (3 files)
        Dzmitry Kazimirchyk made changes -
        Attachment cay-1432.patch [ 12475718 ]
        Hide
        Dzmitry Kazimirchyk added a comment -

        Fixed this by making ListWithPrefetches serializable.
        Also added unit test to ensure that all cached queries will be serializable too.

        Show
        Dzmitry Kazimirchyk added a comment - Fixed this by making ListWithPrefetches serializable. Also added unit test to ensure that all cached queries will be serializable too.
        Gary Jarrel made changes -
        Field Original Value New Value
        Labels cache oscache
        Gary Jarrel created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Gary Jarrel
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development