createCache fails in non-static method

classic Classic list List threaded Threaded
2 messages Options
mike-griggs mike-griggs
Reply | Threaded
Open this post in threaded view
|

createCache fails in non-static method


I am creating a cache with a CacheStoreFactory implementation and a CacheStoreSessionListener. If I set the CacheConfiguration with these fields and then call createCache but in an INSTANCE method I get this exception:


Exception in thread "main" javax.cache.CacheException: class org.apache.ignite.IgniteCheckedException: Failed to validate cache configuration (make sure all objects in cache configuration are serializable): LongCache

In a static method, this does not occur. This can be easily reproduced by modifying the CacheJdbcStoreExample.java in examples. This is happening under Ignite 1.30
 
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: createCache fails in non-static method

Hi!

Most likely you declared the factory or the listener as an anonymous class. Anonymous classes always contain reference to the parent class (LongCache in your case). So if the factory is serialized in the context of LongCache instance, this instance is also serialized. In case of static method this instance doesn't exist, therefore everything works.

I would recommend to convert anonymous classes to private static classes. This will give you more control on what is serialized.

-Val