cloooze
cloooze

Reputation: 173

Update list of entities transactional method

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"));
}

Upvotes: 0

Views: 477

Answers (1)

Asgar
Asgar

Reputation: 2422

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.

Upvotes: 1

Related Questions