Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7551683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:33:34+00:00 2026-05-30T10:33:34+00:00

We are experiencing an odd problem. We get the KeySet of an Oracle Coherence

  • 0

We are experiencing an odd problem. We get the KeySet of an Oracle Coherence cache, but cannot straight-forwardly get the values from the cache, even with no update activity on it.

The following code fails consistently (i.e. outputs “>>>>NULL” because the object is not retrieved). The question is: WHY?

    NamedCache nc = CacheFactory.getCache(cacheName);
    Set<Object> keys = (Set<Object>)nc.keySet();
    for ( Object key : keys ) {
        Object o = nc.get(key);
        if ( o == null ) {
            System.out.println(">>>>NULL:"+keyStr);
        } 
    }

The cache is a partitioned named cache with multiple indices.

The key is an object (not shown) with one instance variable, a HashMap.

The key object also has equals() and hashCode() methods as follows:

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((values == null) ? 0 : values.hashCode());
    return result;
}


@Override
public boolean equals(Object obj) {
    System.out.println("EQUALS");
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    AbstractCacheKey other = (AbstractCacheKey) obj;
    if (values == null) {
        if (other.values != null)
            return false;
    } else if (!values.equals(other.values))
        return false;
    return true;
}

I believe Coherence uses the hash of the serialized key object in this configuration, which would render these two methods irrelevant, except I don’t know this is true for both front cache (local JVM, has localstorage turned off) and back cache (storage node JVM’s).

Some of our code partially solves this problem by rebuilding the key, inserting the values in a standard order. This usually works. I don’t see why this is necessary, since our hashCode() method and Java’s hashCode() for HashMap are, AFAIK, insensitive to the iteration order of the hash. Why it usually, but not always works is also a mystery.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:33:35+00:00Added an answer on May 30, 2026 at 10:33 am

    The answer (thanks, Dimitri) is that the HashMap doesn’t guarantee its serialization ordering, so serialized-hash->deserialize->object-hash->serialize->serialized-hash may result in the second serialized hash being a different byte stream than the first.

    Java makes no guarantees about ordering in a hash, and serialization is dependent on ordering. Serialization can be different from one JVM to anther, and even within the same JVM. Since the internal implementation of a HashMap is a typical in-memory hash, with N buckets, each holding (probably via a linked list) a set of entries whose hash corresponds to the bucket, the order in which entries are put into the hash determines (in a non-specified way) the order in which the keyset iteration will return them. A TreeMap, by comparison, should produce consistent ordering and thus, presumably, consistent serialization.

    Coherence partitioned caches store keys and values in serialized form, so they compute the hash function on the serialized version of the key, and do equality checks on the serialized keys. Even though the serialized stream is equivalent for the purposes of reconstructing the object, it is not guaranteed identical as needed for the hashing and equality checking operations.

    To complicate matters more, in near-cache, the object is kept in deserialized form and hence its equals() and hashCode() methods are used instead.

    Finally, Coherence recommends the use of their proprietary POF serialization, which usually results in reduced serialized size and gives direct control of serialization to the object being serialized.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am experiencing a odd problem. My OnItemSelectedListener seems only works one time, i
I am experiencing some very odd timing behavior from a function I wrote. If
Experiencing jquery in rails through .js.erb templates; but completely puzzled by a simple problem
Edit: Rolled back Wills change as it was wrong I'm experiencing an odd problem
This is a bit of unusual problem that I'm experiencing, but recently one of
I'm experiencing an odd problem where my page's SSL breaks in firefox if I
I've been experiencing this very odd problem lately in Heroku. I develop and test
I'm experiencing a very odd problem with a Java application running under Tomcat. We
I am experiencing an odd behaviour from a TreeView control. As you can see,
I'm experiencing an odd problem when trying to navigate through a table's rows and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.