0

I am implementing a dynamic query logic using JPA specifications on an entity. The entity is having multiple relations with other entities. I am running into the issue of generating too many queries while executing JPA specifications.

Is there a way to combine JPA specifications findAll(specification, page) with EntityGraph so that we can one query generated while executing the same?

user2885295
  • 329
  • 1
  • 4
  • 12

1 Answers1

1

Yes it is absolutely possible to pass EntityGraph using EntityGraphJpaSpecificationExecutor

@Repository
public interface UserRepository
        extends JpaRepository<EntityClassName, DatatypeOfPrimaryKey>, EntityGraphJpaSpecificationExecutor<EntityClassName> {
}

userRepository.findAll(specification, pageable, new NamedEntityGraph(EntityGraphType.FETCH, "graphName"))
SSK
  • 3,444
  • 6
  • 32
  • 59