带有主体和三元运算符的Dynamic Spring @Query

时间:2016-06-15 18:44:51

标签: jpql ternary-operator spring-annotations spring-el principal

根据这个https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions,我应该能够构建一个条件查询:

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

我想要实现的是更改查询的大部分内容。这完全是合成的例子,但它证明了这个想法:

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

上面的查询给出了org.hibernate.hql.internal.ast.QuerySyntaxException:意外的AST节点:?靠近第1行

我尝试了不同的组合,有没有?,',:,#但仍然没有运气。我怀疑由于@Query的限制或者我误解了语法,它要么不可能。任何帮助表示赞赏。

0 个答案:

没有答案
相关问题