[
https://issues.apache.org/jira/browse/GEODE-5845?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16645326#comment-16645326
]
Karen Smoler Miller commented on GEODE-5845:
--------------------------------------------
Why not use an enum type as a key?
# Enums are named constants. The entries in a region with an enum as a key
would be strictly limited to the quantity of listed values/constants for that
enum. For example, the definition
public enum Day \{ SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY,
SATURDAY }
with a key defined as a Day could have a maximum of 7 entries, one for each
day. Unique keys distinguish entries. No duplicate keys are permitted.
# For partitioned regions, the hash of a key determines a bucket. The hash of
an enum uses a local address, making the value transient, and different for
distinct servers. Therefore, different servers would take a key (which is an
enum type) and potentially calculate different buckets (from each other). That
breaks the use of a partitioned region. Further, you cannot define your own
hash() of your enum, so you cannot change this behavior.
Good advice: don't define your hash() method based an enum field/data member of
a compound key for both reasons listed here.
> Document that an enum should never be used for keys
> ---------------------------------------------------
>
> Key: GEODE-5845
> URL: https://issues.apache.org/jira/browse/GEODE-5845
> Project: Geode
> Issue Type: Improvement
> Components: docs
> Reporter: Karen Smoler Miller
> Assignee: Karen Smoler Miller
> Priority: Major
>
> Maybe it should be obvious, but an enum type should never be used for an
> entry key. To make this explicitly clear, add this advice to the docs.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)