79408228

Date: 2025-02-03 08:51:33
Score: 1
Natty:
Report link

save(entity):

Saves the entity but does not immediately commit the changes to the database. Hibernate may delay writing changes until the transaction is committed or until it is required (e.g., when another query forces a flush). If the entity is managed (attached to the persistence context), Hibernate may optimize and delay the actual UPDATE statement.

saveAndFlush(entity):

Saves the entity and immediately flushes the changes to the database. Ensures the update is reflected in the database right away. Useful when you need to be sure the data is stored before executing another operation that depends on it.

  1. orderRepository.save(productOrder) // Changes are not immediately written to the database
  2. orderRepository.saveAndFlush(productOrder) // Changes are written to DB immediately
Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Suresh