Requirements for Using Custom Classes in Data Caching
Follow these guidelines to use custom domain classes for your cached entry keys and values.
CLASSPATH must include classes for all objects the member accesses.
- For Java applications, use the standard Java
- For the cache server process, use the
CLASSPATHenvironment variable or the
gfsh start server’s
--classpathparameter. See Running Geode Server Processes.
Data is sent between clients and servers in serialized form and the server stores client data in serialized form. The server does not need to deserialize data to send it to another client or to access it through a
PDXInstance, but it does need to deserialize it to access it in other ways. The server
CLASSPATH must include the classes for:
- All entry keys
- Entry values in regions that the server persists to disk
- Entry values the server accesses for any reason other than access using a
PdxInstanceor transfer of the full entry value to a client
For information on
PdxInstances, see Data Serialization.
Geode serializes data entry keys and values for distribution, so all data that Geode moves out of the local cache for any reason must be serializable. Additionally, partitioned regions store data in serialized form. Almost every configuration requires serialization.
For information on the requirements and options for data serialization, see Data Serialization.
The region uses hashing on keys. If you define a custom class to use as a key, for the class, override:
hashCode. The default
Objectuses identity, which is different in every system member. In partitioned regions, hashing based on identity puts data in the wrong place. For details, see the Java API documentation for
Do not call
hashCode() on an
enum type data member
within the key’s custom
hashCode() may not be overridden,
and its hash is based upon an address.
Therefore, an enumerated type’s
hashCode() return value can be different
on each server, violating the restriction that
hashCode() must return
the same value on every server that hosts the region.