Spring data repositories, predicates and projection.

121 views
Skip to first unread message

Phil Scadden

unread,
Oct 12, 2016, 4:46:05 AM10/12/16
to Querydsl
Working entity BoreHole:
  ID
  NAME
  LATITUDE
  LONGITUDE
  OPERATOR
  TOTAL_DEPTH
  AQUIFER
  .....
  (many many attributes)

I have web form that allows a user to create quite complex querys (brackets, and, or) for selecting these bores. I found it convenient to use PathBuilder to create a BooleanExpression predicate from this data so I can go;
        QBoreHole boreHole = QBoreHole.boreHole;
        Predicate predicateBH = BoreHolePredicateBuilder(queryString);
        Iterable<BoreHole> bhList = boreHoleRepository.findAll(predicateBH);

All well and good - except that BoreHole is a very heavyweight object and what I want is a projection that just returns the first four fields.

queryDSL queries could do this with .list - but the .where clause much harder to construct than the predicate. I could create a separate repository for the projection but I feel that I have too many repositories already. Is there anyway to combine predicate-based repository with projection?

Reply all
Reply to author
Forward
0 new messages