What is the best way for creating dynamic queries using Spring Data JPA?
I want to create custom projection of many tables joined together in many different ways (5-10) for performance reasons. Something simillar to criteria, and projections in previous versions of hibernate.
For example:
I have 6 tables: A, B, C, D, E, F
.
A
, B
and C
are always joined together (ABC
) and create 'result'.
Tables D
, E
, F
are are joined to ABC
only when user fills certain search fields. User might search by any of D,E,F
column, or all of them at once.
I want to achieve projection like this: Result(A.id, A.name, B.code, C.description
).
I don't want to use @Query
annotation because there's a lot of different possibilites how these tables can be joined.