title: Spring - Data persisted by JdbcTemplate unable to be seen by JpaRepository
body: <p>I am building a Spring Boot application which requires the need for persistence via JDBC and selecting/reading via JPA/Hibernate. I have implemented both of these types of operations using Spring's JdbcTemplate and Spring Data's JpaRepository.</p>
  
  <p>After I persist using JdbcTemplate I am unable to see the data via JpaRepository even though they share the same datasource. I am able to read the data if I use JdbcTemplate.</p>
  
  <p><strong>NOTE:</strong> I am using two data sources. One is configured in another class without the @Primary annotation using its own entity manager factory and transaction manager, which is why I've needed to explicitly define it below using Spring Boot's default bean terminology "transactionManager" and "entityManagerFactory".</p>
  
  <p>The following is my embedded database configuration for the primary beans:</p>
  
  <pre><code>@Configuration
  @EnableJpaRepositories(basePackages = {"com.repository"})
  public class H2DataSourceConfiguration {
  
      private static final Logger log = LoggerFactory.getLogger(H2DataSourceConfiguration.class);
  
      @Bean(destroyMethod = "shutdown")
      @Primary
      public DataSource dataSource() {
          return new EmbeddedDatabaseBuilder()
                  .setType(EmbeddedDatabaseType.H2)
                  .setName("dataSource")
                  .build();
      }
  
      @Bean
      @Primary
      public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder, DataSource dataSource) { 
          return builder
              .dataSource(dataSource)
              .packages("com.my.domain", "org.springframework.data.jpa.convert.threeten")
              .build();
      }
  
      @Bean
      @Primary
      public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
          JpaTransactionManager jpaTransactionManager = new JpaTransactionManager(entityManagerFactory);
          return jpaTransactionManager;
      }
  }
  </code></pre>
  
  <p>The persistence happens in a different transaction to the reading of the data, however they share the same service.
  Both operations happen within the @Transactional annotation. Both repository beans are specified in the same service and also contain the @Transactional annotation. The service looks as follows:</p>
  
  <pre><code>@Service
  @Transactional
  public class MyServiceImpl implements MyService {
  
      private static final Logger log = LoggerFactory.getLogger(MyServiceImpl.class);
  
      @Autowired
      private MyJpaRepository myJpaRepository;
  
      @Autowired
      private MyJdbcRepository myJdbcRepository;
  
      ...
  }
  </code></pre>
  
  <p>MyJdbcRepositoryImpl.java:</p>
  
  <pre><code>@Repository
  @Transactional(propagation = Propagataion.MANDATORY)
  public class MyJdbcRepositoryImpl implements MyJdbcRepository {
  
      @Autowired
      private NamedParameterJdbcTemplate jdbcTemplate;
  
     // methods within here all use jdbcTemplate.query(...)
  }
  </code></pre>
  
  <p>MyJpaRepository.java:</p>
  
  <pre><code>@Repository
  @Transactional(propagation = Propagataion.MANDATORY)
  public interface AcquisitionJpaRepository extends JpaRepository&lt;AcquisitionEntity, Long&gt; {
  
  }
  </code></pre>
  
  <p>Is it at all possible that the jdbctemplate calls are saving to a different h2 database?</p>