0

I was trying to use QuerydslJpaRepository in my project, but it’s deprecated, and it is recommended to use QuerydslPredicateExecutor instead. However, QuerydslPredicateExecutor does not have the save() method, which is present in QuerydslJpaRepository.

How can I resolve this issue?

ib.
  • 27,830
  • 11
  • 80
  • 100
Sanjay
  • 165
  • 1
  • 13

1 Answers1

1

Your repository should extend not only QueryDslPredicateExecutor, but JpaRepository which contains save method (inherited from CrudRepository).

public interface YourEntityRepository 
    extends JpaRepository<YourEntity, ID>, QueryDslPredicateExecutor<YourEntity> {
}
Oleksii Valuiskyi
  • 2,691
  • 1
  • 8
  • 22
  • If my interface extends from QueryDslPredicateExecutor then i am getting 8 errors in my implementation class as such as -> The type must implement the inherited abstract method QuerydslPredicateExecutor.findAll(OrderSpecifier>...) ...its for all finder, count and exits methods. I don't want to do that. Is there any other way to do this? – Sanjay Aug 21 '20 at 19:41
  • No need to implement repository. Spring implement it for you – Oleksii Valuiskyi Aug 21 '20 at 19:59
  • I need to have an implementation class as i need some additional methods. I have use composition to have QueryDslPredicateExecutor in my implementation class but it does not have save() method. – Sanjay Aug 21 '20 at 20:01
  • You can try to make your repository implementation extended from SimpleJpaRepository which implements JpaRepository – Oleksii Valuiskyi Aug 21 '20 at 20:05
  • My implementation class already extends from some base class. Can i use both QueryDslPredicateExecutor and SimpleJpaRepository in my implementation class using composition and then use SimpleJpaRepository for only save() operation? I am not sure if 2 repositories for same domain object will create any issue. – Sanjay Aug 21 '20 at 20:20
  • You 'd better use BaseRepository extends JpaRepository for every repository https://stackoverflow.com/questions/55107526/spring-jpa-base-repository – Oleksii Valuiskyi Aug 21 '20 at 20:55
  • If my BaseRepository extends from JpaRepository then will there be any issue of having two repositories for same entity. I.e my implementation class is also a repository and QueryDslPredicateExecutor is also present in the implementation class as member variable. Should i use JpaRepository without specifying entity class? – Sanjay Aug 21 '20 at 21:25
  • So now i have one interface extending from JpaRepository, QueryDslPredicateExecutor. I am just autowiring this in my implementation class and keeping my custom interface as is. So i have two interfaces now. Does that look fine? – Sanjay Aug 21 '20 at 21:59
  • You should have one repository. It is complicated to explain how to do it using comments. You shoud ask another question providing your code. More info how to create custom repository here https://docs.spring.io/spring-data/data-commons/docs/1.6.1.RELEASE/reference/html/repositories.html **Chapter 1.3 Custom implementations for Spring Data repositories** – Oleksii Valuiskyi Aug 22 '20 at 05:39
  • I have followed the accepted answer from the below post. https://stackoverflow.com/questions/11880924/how-to-add-custom-method-to-spring-data-jpa – Sanjay Aug 23 '20 at 02:54