2

According to this https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions I should be able construct a conditional query:

@Query("select o from BusinessObject o where o.owner.emailAddress like "+
  "?#{hasRole('ROLE_ADMIN') ? '%' : principal.emailAddress}")
List<BusinessObject> findBusinessObjectsForCurrentUser();

What I'm trying to achieve is to change a larger part of a query. This is entirely synthetic example, but it demonstrates the idea:

@Query("select p from Project p where " + "?#{hasRole('ROLE_ADMIN') ? 'p.status='PRIVATE'':p.'status='PUBLIC''}")
public Page<Project> findAll(Pageable pageable);

The query above gives org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: ? near line 1

I have tried different combinations with and without ?, ', :, # but still no luck. I suspect that it's either not possible due to the limitations of @Query or I misunderstand the syntax. Any help is appreciated.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.