3

I have a Spring Boot application annotated with @EnableJpaRepositories(repositoryBaseClass = CommonRepository.class). Almost all of the repositories need to implement some custom logic which is done using repositoryBaseClass.

Is there a way to create a repository that will be excluded from repositoryBaseClass mechanism?

igobivo
  • 433
  • 1
  • 4
  • 17

1 Answers1

2

You could write a repository that doesn't implement one of the Spring Data JPA Repository interfaces. Essentially you would write a repository like you would do without Spring Data JPA.

public class YourRepo /* No Spring Data interface here! */ { 

    @Autowired
    private EntityManger entityManager;

    public add(Something entity) {
        entityManager.merge(entity);
    }
}

Otherwise you would need to create different configurations (with @Configuration) if you you want to use different repositoryBaseClasses.

deamon
  • 89,107
  • 111
  • 320
  • 448
  • And probably adjust component scan, so the `Configuration` with `repositoryBaseClass = CommonRepository.class` doesn't pick up the specific other `Repository` – Lino Apr 26 '19 at 08:12
  • 1
    huh, yes, the idea of not using spring for something didn't occur to me :) – igobivo Apr 26 '19 at 10:14