使用querydsl和jpa进行自定义查询

时间:2017-06-09 09:14:57

标签: java jpa querydsl

是否可以使用查询dsl编写自定义查询?

e.g。 (自我加入)

SELECT test1.SURNAME, test2.SURNAME
FROM Test test1
LEFT OUTER JOIN Test test2 ON test1.SUPERVISOR_WARRANT_NUMBER = test2.WARRANT_NUMBER
WHERE test1.SURNAME LIKE '%Your name%';

所以我想用

做上面的事情
@Repository
public interface Test <TestModel> , QueryDslPredicateExecutor<TestModel> {
    @Override
    @Query("SELECT test FROM Test") /*do outer self join in Query*/
    Page<TestModel> findAll(Predicate prdct, Pageable pgbl);
}

我上面代码的例外是:

org.springframework.dao.InvalidDataAccessApiUsageException: Parameter with that position [1] did not exist; nested exception is java.lang.IllegalArgumentException: Parameter with that position [1] did not exist

如果无法实现以上目标,那么在java中使用分页编写动态查询(使用各种连接)的最佳方法是什么?

0 个答案:

没有答案