是否有任何形式可以使用spring-data jpa对查询方法中的条件进行分组?

时间:2013-06-19 20:21:42

标签: java spring jpa spring-data spring-data-jpa

例如,结果sql应为:

SELECT * FROM transaction t WHERE t.type = 4 AND (t.status = 1 OR t.value = 2)

但是在查询方法方面,我无法确定它必须如何

public List<Transaction> findByTypeAndStatusAndValue(int type, int status, int value);

我不确定上面的代码是否按预期工作。

1 个答案:

答案 0 :(得分:1)

您始终可以提供自定义查询:

@Query("select t from Transaction t where t.type = ?1 and (t.status = ?2 or t.value = ?3)")
public List<Transaction> findByTypeAndStatusOrValue(int type, int status, int value);