I've run into this issue myself. One important thing you need to do that I
don't see on the configuration is setting PDX serialization on the client.
I've done something like the following:
<gfe:client-cache id="clientCache" pool-name="gemfirePool"
pdx-serializer-ref="pdxAutoSerializer" />
<bean id="pdxAutoSerializer"
class="com.gemstone.gemfire.pdx.ReflectionBasedAutoSerializer">
<constructor-arg>
<value>classes to serialize</value>
</constructor-arg>
</bean>
That way, as clients are inserting objects, they will be PDX serialized.
Another thing I've seen happen is that there are some rules about objects
(and contained objects) needing a default (no arg) constructor. If GemFire
detects this isn't the case, it will revert to Java Serializable. You can
enforce this by adding the 'check-portability' parameter to the serializer
constructor. This will cause serialization to fail if you don't meet the
requirements for PDX Serialization.
Mark
On Thu, Dec 3, 2015 at 11:30 AM, Jason Huynh <[email protected]> wrote:
> Hi Nikhil,
>
> For point (a), if the objects are stored as java serializable, I believe
> when deserializing on the server, the class files would need to be on the
> server class path because at that point it is not pdx serialized.
>
> I think you would need to have the clients serialize with pdx or else you
> will get this behavior. I am not sure but I don't think the server can
> automatically convert from java serialization to pdx serialization in this
> scenario, especially because the information on how to pdx serialize would
> be contained in the class which isn't on the server.
>
> Even if the server knew about the class file, I am not sure if that auto
> conversion would happen once it has been serialized from the client.
> Someone that knows pdx a bit better may be able to answer this.
>
> -Jason
>
> On Thu, Dec 3, 2015 at 10:12 AM, Nikhil Chandrappa <[email protected]
> > wrote:
>
>> Hi,
>>
>> *Issue*:
>>
>> Unable to query the Gemfire region. I get the following exception
>>
>> gfsh>query --query="SELECT firstName FROM /Account WHERE id=1"
>>
>> Result : false
>> startCount : 0
>> endCount : 20
>> Message : A ClassNotFoundException was thrown while trying to
>> deserialize cached value.
>>
>> NEXT_STEP_NAME : END
>>
>> *Context*:
>>
>> We are using Spring Data Gemfire caching for storing the cached objects in
>> to Gemfire. We want to be able to query the Gemfire region to see the
>> cache
>> data.
>>
>> Following are the constraints we have,
>>
>> 1. we cannot enable the PDX serializer on the client
>> 2. Domain objects cannot be placed on the Gemfire server classpath
>>
>> *Analysis:*
>>
>> *a)*
>> we have configured Gemfire cluster with PDX serialization, however Gemfire
>> will store the objects as Java Serialized object. is this a valid
>> behavior?
>>
>> *b)*
>> If we use the query service like below,
>>
>> // Log for debugging
>>
>> cache.getLogger().info("Executing Query: "+ queryStr);
>>
>> SelectResults results = (SelectResults) query.execute();
>>
>> // Log for debugging
>>
>> cache.getLogger().info("After Query Execution");
>>
>> I am getting "A ClassNotFoundException was thrown while trying to
>> deserialize cached value."
>>
>> What are the options that we have for querying the regions with
>> constraints
>> that are mentioned above? We want to able to query the Gemfire regions
>> without having the domain objects present on the classpath.
>>
>> *Configurations:*
>>
>>
>> ClientCache.xml
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <beans xmlns="http://www.springframework.org/schema/beans"
>> xmlns:cache="http://www.springframework.org/schema/cache"
>> xmlns:context="http://www.springframework.org/schema/context"
>> xmlns:gfe="http://www.springframework.org/schema/gemfire"
>> xmlns:gfe-data="http://www.springframework.org/schema/data/gemfire
>> "
>> xmlns:p="http://www.springframework.org/schema/p"
>> xmlns:util="http://www.springframework.org/schema/util"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation="
>> http://www.springframework.org/schema/beans
>> http://www.springframework.org/schema/beans/spring-beans.xsd
>> http://www.springframework.org/schema/cache
>> http://www.springframework.org/schema/cache/spring-cache.xsd
>> http://www.springframework.org/schema/context
>> http://www.springframework.org/schema/context/spring-context.xsd
>> http://www.springframework.org/schema/gemfire
>> http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
>> http://www.springframework.org/schema/data/gemfire
>> http://www.springframework.org/schema/data/gemfire/spring-data-gemfire.xsd
>> http://www.springframework.org/schema/util
>> http://www.springframework.org/schema/util/spring-util.xsd
>> ">
>>
>>
>> <util:properties id="clientConfigurationSettings">
>> <prop key="pivotal.cache.specs.directory">specs</prop>
>> </util:properties>
>>
>> <context:property-placeholder location="classpath:server.properties"
>> properties-ref="clientConfigurationSettings"/>
>>
>> <util:properties id="gemfireCacheConfigurationSettings">
>> <prop key="log-level">config</prop>
>> <prop key="cluster-ssl-enabled">true</prop>
>> <prop
>>
>> key="cluster-ssl-truststore">/Users/nchandrappa/Documents/grid/security/cacerts.keystore</prop>
>> <prop key="cluster-ssl-truststore-password">password</prop>
>> </util:properties>
>>
>> <gfe:pool id="serverConnectionPool">
>> <gfe:locator host="localhost" port="10334"/>
>> </gfe:pool>
>>
>> <gfe:client-cache properties-ref="gemfireCacheConfigurationSettings"
>> id="gemfireCache" pool-name="serverConnectionPool"/>
>>
>> <cache:annotation-driven/>
>>
>> <bean id="cacheManager"
>>
>> class="pivotal.gemfire.core.cache.manager.RegionCreationGemFireCacheManager"
>> p:cache-ref="gemfireCache"/>
>> <bean class="pivotal.gemfire.core.cache.manager.RegionCreator" />
>>
>> <context:component-scan base-package="pivotal.client"/>
>>
>> </beans>
>>
>>
>> ServerCache.xml
>>
>> <?xml version="1.0"?>
>> <!DOCTYPE cache PUBLIC
>> "-//GemStone Systems, Inc.//GemFire Declarative Caching 8.0//EN"
>> "http://www.gemstone.com/dtd/cache8_0.dtd">
>>
>> <cache>
>> <pdx read-serialized="true" />
>> </cache>
>>
>> Thanks,
>> Nikhil
>>
>
>
--
*Mark Secrist | Sr Manager, **Global Education Delivery*
[email protected]
970.214.4567 Mobile
*pivotal.io <http://www.pivotal.io/>*
Follow Us: Twitter <http://www.twitter.com/pivotal> | LinkedIn
<http://www.linkedin.com/company/pivotalsoftware> | Facebook
<http://www.facebook.com/pivotalsoftware> | YouTube
<http://www.youtube.com/gopivotal> | Google+
<https://plus.google.com/105320112436428794490>