0

I need to do the following in my @Transactional Class

  1. Do changes to data (empty logs field) inside a DAO object and save to PostGresql DB
  2. Revert the changes and save to ElasticSearch (with the id generated in the same DAO object from first commit return result).

Here is how the code is

    emptylogsField(testCaseResponses); //Data modifications
    Iterable<TestCaseResponse> result = 
    PGRepository.saveAll(converter.convertToEntities(testCaseResponses));
    PGRepository.flush();
    putBackLogs(result); // Data modifications
    result = ESRepository.saveAll(result);

The problem is the same data is getting saved in both repositories. The flush() is not working? Please help.

Abdullah
  • 139
  • 3
  • 17
  • 1
    Flush method isn't dedicated to rollback changes. Please take a look at [this](https://stackoverflow.com/questions/4275111/correct-use-of-flush-in-jpa-hibernate) topic which helps you understand the purpose of using the flush method. Anyway, your approach is strange, why are you using database only to assign id for entities? – Kamil W Jan 25 '19 at 07:26
  • @KamilW. , I was not using Flush method for rollback. I want to push my changes to DB in the middle of a Spring Transaction. So that I can again change the DAO object and persist to another repository based on my business logic. – Abdullah Jan 25 '19 at 12:12

0 Answers0