i read that upon session.flush()
The
data will be synchronized (but not committed) when session.flush() is called
what is synchronized with what..
whether it is DB state that will come to memory by querying or
memory state will be copied to Db ?
clarify this plz..
Calling
session.flush()will cause SQL statements to be generated for all of the changes you have made, and those SQL statements to be executed on the database, within the sessios transaction scope.The last line will cause an
UPDATEstatement on the database. However, depending on how you handle transactions in your applications, this change might not be visible to other users before you commit the transaction held by the section.While flushing is not really a bi-directional operation, it can be used to ensure that an auto generated identifier is assigned to a new entity object. If the
Carclass is mapped to a database table with an auto incrementing identifier, you can use flush to ensure that this identifier is available on the domain object in your application code:Say you want to send an email with a link to the newly created car (ok, a user account would have made more sense), but if the mail cannot be sent, you wish to rollback your transaction. Flushing the session allows you to do this.