Flushing the Session simply gets the data that is currently in the session synchronized with what is in the database. However, just because you have flushed, doesn't mean the data can't be rolled back.
Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.
A database transaction is a unit of work performed against a database management system or similar system that is treated in a coherent and reliable way independent of other transactions. A database transaction, by definition, must be atomic, consistent, isolated and durable. These properties of database transactions are often referred to by the acronym ACID.
Commit will make the database commit - Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory. ie. it will update or insert into your tables in the running transaction, but it _may_ not commit those changes (this depends on your flush mode). When you have a persisted object and you change a value on it, it becomes dirty and hibernate needs to flush these changes to your persistence layer. It may do this automatically for you or you may need to do this manually, that depends on your flush mode, check http://www.hibernate.org/hib_docs/v3/api/org/hibernate/FlushMode.html for further details on which flush mode is the right one for you.
Best Regards,<br />Vipin<br />MCA, SCJP5, SCWCD in progress
My test tells me the session.flush() does not make the data visible to other clients. It is available only after the commit.
And I also notice when I set the batch size from 10, 100, 1000, 10000, the performance is pretty much the same. 1%-2% difference with
Anup Bansal wrote:I have one question with regards to flushing and Commit.
I want to insert around 50000 records using hibernate in a single trnasaction. The suggested apporach is:
My question is: will the records flushed by the call to session.flush() (Line 1) and before the commit is perfomred (Line 2) be visible in the database from another applicaiton/session?