DefaultJpaRepository extends CrudRepositorySupport { public Object saveAndFlush(Object entity) { log.info("Saving entity " + entity + " to the data store."); final Object saved = save(entity); log.info("Going to flush the data store after the save"); flush(); return saved; }  void flush(); Iterable deleteInBatch(Iterable entities); Iterable deleteAllInBatch(); Object getOne(Object key); Object saveAndFlush(Object entity);  }
@Test public void testSaveAndFlush() { final DefaultJpaRepository repository = new DefaultJpaRepository(); repository.setKeyGenerator(new UUIDKeyGenerator()); repository.setRepositoryMetadata(repositoryMetadata); final SpyingDataStore<String, Person> dataStore = new SpyingDataStore<>(this.dataStore, new AtomicLong()); repository.setDataStore(dataStore); final Person entity = new Person().setId("1"); repository.saveAndFlush(entity); assertThat(dataStore.getRequests().get(dataStore.getRequests().size() - 1).getOperation(), is(Operation.FLUSH)); assertThat(dataStore.retrieve("1"), is(entity)); }