I fetch a list of objects using CrudRepository object for my entity class. I want to duplicate the list in database with some field for every Object in the list modified. How do I achieve it with same repository object?
The sample code is as follows. It modifies the existing rows in Database. I want it to append the modifications as new rows in the database.
@Autowired TestRepository testRepository; List<SampleClass> sampleList = testRepository.findAllBySomeId(id); sampleList.forEach(i -> i.setSomeValue(1234)); testRepository.saveAll(testRepository);
Do I need to make separate Repository object? Is it possible with same Repository object annotated with @Autowired?