3 Replies Latest reply on Jun 8, 2017 5:50 AM by Adrian Nistor

    Getting Just the List of Keys as a Result from a DSL Query

    Matthew Bachmann Newbie

      I've been trying to use the Infinispan Query DSL (org.infinispan.query.dsl) to create queries against a cache.  Ideally, I would like the result of the query to not return the objects but just the keys for the objects.  It seems that this is possible using the Hibernate Query DSL, but would ideally like to do this from the Infinispan Query DSL, since it's simpler and more straight forward.  I've read the docs, and searched the forums and the bug tracker, but cannot seem to find anything about this.


      From a little bit of RTFSing it seems that there is a constant org.infinispan.query.ProjectionConstants.KEY which is used by org.infinispan.query.impl.ProjectionConverter, but this doesn't seem to work when passed to QueryBuilder.select, and just complains of the property "__ISPN_Key" not being on the entity.


      Am I barking up the right tree?  Is there some other incantation that needs to be made?  Or is this just a non-existent feature, or maybe a bug given the existence of ProjectionConstants.KEY?


      Thanks for any help,




      Here's my testing code:


      public class QueryDslKeyProjection
        public static class TestClass
            private String attr;
            public TestClass(String attr) 
                this.attr = attr;
            @Field(index = Index.YES)
            public String getAttr()
                return this.attr;
        public static void main(String[] args)
            EmbeddedCacheManager manager = new DefaultCacheManager();
            Configuration config = (new ConfigurationBuilder())
            manager.defineConfiguration("foo", config);
            Cache<String,TestClass>  cache = manager.getCache("foo");
            cache.put("key1", new TestClass("value1"));
            cache.put("key2", new TestClass("value2"));
            cache.put("key3", new TestClass("value3"));
            QueryFactory queryFactory = org.infinispan.query.Search.getQueryFactory(cache);
            Query        query = queryFactory.from(TestClass.class)
            List<String> keys = query.list();
            System.out.println("keys: "+keys);