Tom Donohue Tom Donohue

Infinispan Query DSL: quick example

How do you use the Query DSL in Infinispan? How do you search for objects in the in-memory database that have certain properties?

First add the infinispan-query Maven dependency:


Then you need to add annotations to the fields that you’d like to index on your object. You can add annotations on both fields and methods:


public class Worker {

    private Address workAddress;
    private Address homeAddress;

    public String getHomeAddressLine1() {
        return homeAddress.getLine1();


By default, this field will now be searchable using the property homeAddressLine1 (yes, getter methods are resolved to camelCase names):

QueryFactory qf = Search.getQueryFactory(cache.getCache("yourCacheName"));

Query q = qf.from(Worker.class)
    .having("homeAddressLine1").eq("1 High Street")

List<Worker> list = q.list();


What do you think? You can use Markdown in your comment.

To write code, indent each line with 4 spaces. Or, to paste a lot of code, you can put it in and share the link in your comment.