Home > Enterprise >  Update list of entities transactional method
Update list of entities transactional method

Time:05-22

Will all the cars be black (in the database) after leaving the method?

@Transactional
public void test() {
    List<Car> cars = carDao.findAll();
    cars.forEach(car -> car.setColor("black"));
}

CodePudding user response:

Yes, all the elements in the List will be updated to "black" into your database after the method ends. You're most probably looking for the answer of why is doesn't require any update or merge method call.

@Transactional makes it a transaction and at the end of the transaction, the changes are flushed into database since transactions must be committed or rollbacked at the end of a transaction.

  • Related