Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indices and Comparable<T>: not documented #3024

Closed
otaconix opened this issue Jul 18, 2014 · 2 comments
Closed

Indices and Comparable<T>: not documented #3024

otaconix opened this issue Jul 18, 2014 · 2 comments
Assignees
Milestone

Comments

@otaconix
Copy link

Indices get explained in the Hazelcast documentation. However, it fails to mention that every indexed property type needs to be of a subtype of Comparable. Putting an index on a non-comparable type results in runtime ClassCastExceptions.

Please make this explicit in the documentation!

Sample code to demonstrate the problem:

import java.io.Serializable;

import com.hazelcast.config.Config;
import com.hazelcast.config.MapConfig;
import com.hazelcast.config.MapIndexConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;

public class MainClass {

    private static final String MAP_NAME = "mymap";

    public static void main(String[] args) {
        HazelcastInstance instance = Hazelcast.newHazelcastInstance();
        Config config = instance.getConfig();
        MapConfig mapConfig = config.getMapConfig(MAP_NAME);
        mapConfig.addMapIndexConfig(new MapIndexConfig("other", true)); // Also happens on unordered indexes

        IMap<NonComparable, Object> testMap = instance.getMap(MAP_NAME);
        NonComparable other = new NonComparable(null);

        testMap.put(new NonComparable(other), new NonComparable(other));

        instance.shutdown();
    }

    private static class NonComparable implements Serializable {

        NonComparable other;

        public NonComparable(NonComparable other) {
            this.other = other;
        }
    }
}
@Serdaro
Copy link
Contributor

Serdaro commented Aug 1, 2014

A note added to the Indexing section under Distributed Query. It reads: "Non-primitive types to be indexed should implement Comparable".

@Serdaro Serdaro closed this as completed Aug 1, 2014
Serdaro added a commit that referenced this issue Aug 1, 2014
@pveentjer
Copy link
Contributor

Very strange there is a dependency on Comparable for an unordered index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants