// QueryBuilder is the sessionFactory for queries
QueryBuilder builder = session.getQueryBuilder();
// QueryDomainType is the main interface
QueryDomainType<Employee>dobj = builder.createQueryDefinition(Employee.class);
// parameter
PredicateOperand param1 = dobj.param("param1");
PredicateOperand param2 = dobj.param("param2");
// property
PredicateOperand propertyMagic = dobj.get("magic");
PredicateOperand propertyId = dobj.get("id");
// where
// param1 is used in two different places but same type (int) in both
dobj.where(propertyMagic.equal(param1).and(propertyId.between(param1, param2)));
Query<Employee> query = session.createQuery(dobj);
query.setParameter("param1", 4);
query.setParameter("param2", 5);
List<Employee> result = query.getResultList();
errorIfNotEqual("Wrong size of result", 1, result.size());