troubleshooting Question

How can I sort a field from Swagger if the query contains a Join?

Avatar of ltpitt
ltpitt asked on
Java* swaggerSQL
2 Comments1 Solution120 ViewsLast Modified:
Hi all,

I serve using Spring Boot via Swagger the following endpoint:

   @Query("select a from Table a " +
      " join a.team t " +
      " join a.user u " +
      " join a.role r " +
      " where lower(t.name) like lower(concat('%', :filter, '%'))" + SQLESCAPE +
      " or lower(t.field1) like lower(concat('%', :filter, '%'))" + SQLESCAPE +
      " or lower(t.field2) like lower(concat('%', :filter, '%'))" + SQLESCAPE +
      " or lower(u.field3) like lower(concat('%', :filter, '%'))" + SQLESCAPE +
      " or lower(r.field4) like lower(concat('%', :filter, '%'))" + SQLESCAPE)
   )
   Page<Role> findRolesByTypeInAndFilter(@Param("filter") String filter, Pageable pageable);

It works perfectly but when the user wants to sort I can only sort fields that are NOT in the joins (only fields available in Table).

If user specify the full field name (e.g. u.field3) it works perfectly,

What can I do to let the user just use, for examlpe, field3 for sorting?

Thanks!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros