在 Spring Data JPA Repository 中,我需要指定多个执行相同操作的方法(例如 findAll),但指定不同的 @EntityGraph 注释(目标是优化方法以在不同服务中使用)。
埃斯。
@Repository
public interface UserRepository extends JpaSpecificationExecutor<User>, JpaRepository<User, Long> {
@EntityGraph(attributePaths = { "roles" })
findAll[withRoles](Specification sp);
@EntityGraph(attributePaths = { "groups" })
findAll[withGroups](Specification sp);
etc...
}
在Java中我们不能多次签名相同的方法,那么如何管理呢?
不使用JPQL可以吗?
谢谢,
加布里埃尔