title: Spring JPA Base Repository
body: <p>I have created a custom repository to override persistence methods and tried to wire it up as described in the <a href="https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.custom-behaviour-for-all-repositories" rel="nofollow noreferrer">spring docs</a>. I receive no errors, all entities and repositories are found on startup, and when I call repo.saveAll(entities), persistence works normally. However, my custom code is never called. I have added log statements and even thrown RuntimeExceptions in my code, just to see if it's being executed, but it's definitely being ignored. What step have I missed?</p>
  
  <pre><code>@Configuration
  @Profile("test")
  @EnableJpaRepositories(repositoryBaseClass = SetClientInfoRepositoryImpl.class,
          basePackages = {"gov.penndot.hwy.apras.common.repository" }, 
          entityManagerFactoryRef = "serviceEntityManagerFactory", 
          transactionManagerRef = "serviceTransactionManager")
  public class TestDatabaseConfig {
  
      @Bean(name = "serviceDataSource")
      public DataSource dataSource() {
          DriverManagerDataSource dataSource = new DriverManagerDataSource();
          dataSource.setDriverClassName("org.h2.Driver");
          dataSource.setUrl("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1");
          dataSource.setUsername("sa");
          dataSource.setPassword("sa");
  
          return dataSource;
      }
  
      @Bean
      public EntityManagerFactoryBuilder entityManagerFactoryBuilder() {
          return new EntityManagerFactoryBuilder(new HibernateJpaVendorAdapter(), new HashMap&lt;String, Object&gt;(), null);
      }
  
      @Bean(name = "serviceEntityManagerFactory")
      public LocalContainerEntityManagerFactoryBean serviceEntityManagerFactory(EntityManagerFactoryBuilder builder,
              @Qualifier("serviceDataSource") DataSource dataSource) {
  
          return builder
                  .dataSource(dataSource)
                  .packages("stuff")
                  .persistenceUnit("service")
                  .build();
      }
  
      @Bean(name = "serviceTransactionManager")
      public PlatformTransactionManager transactionManager(
              @Qualifier("serviceEntityManagerFactory") EntityManagerFactory serviceEntityManagerFactory) {
          return new JpaTransactionManager(serviceEntityManagerFactory);
      }
  </code></pre>
  
  <p>Repository:  </p>
  
  <pre><code>@NoRepositoryBean
      public class SetClientInfoRepositoryImpl&lt;T, ID extends Serializable&gt; extends SimpleJpaRepository&lt;T, ID&gt; {
          private static final Logger log = LoggerFactory.getLogger(SetClientInfoRepositoryImpl.class);
          private final EntityManager em;
  
          public SetClientInfoRepositoryImpl(JpaEntityInformation&lt;T, ID&gt; entityInformation, EntityManager entityManager) {
              super(entityInformation, entityManager);
              this.em = entityManager;
          }
  
          @Transactional
          @Override
          public &lt;S extends T&gt; S save(S entity) {
              setClientInfo();
              return super.save(entity);
          }
  
          @Transactional
          @Override
          public void deleteById(ID id) {
              setClientInfo();
              super.deleteById(id);
          }
  
          @Transactional
          @Override
          public void delete(T entity) {
              setClientInfo();
              super.delete(entity);
          }
  
          @Transactional
          @Override
          public void deleteAll(Iterable&lt;? extends T&gt; entities) {
              setClientInfo();
              super.deleteAll(entities);
          }
  
          @Transactional
          @Override
          public void deleteInBatch(Iterable&lt;T&gt; entities) {
              setClientInfo();
              super.deleteInBatch(entities);
          }
  
          @Transactional
          @Override
          public void deleteAll() {
              setClientInfo();
              super.deleteAll();
          }
  
          @Transactional
          @Override
          public void deleteAllInBatch() {
              setClientInfo();
              super.deleteAllInBatch();
          }
  
          @Transactional
          @Override
          public &lt;S extends T&gt; S saveAndFlush(S entity) {
              setClientInfo();
              return super.saveAndFlush(entity);
          }
  
          @Transactional
          @Override
          public &lt;S extends T&gt; List&lt;S&gt; saveAll(Iterable&lt;S&gt; entities) {
              setClientInfo();
              super.saveAll(entities);
              throw new RuntimeException("foo");
          }
  
          private void setClientInfo() {
              log.debug("Entering setClientInfo method");
              [stuff]
          }
      }
  </code></pre>