I store an entity, then I need to execute native query (it's done through doWork), and for successful execution of the query record[s] that represent entity must exist in database (to be more precise, it must be available within the same transaction), so I guess calling flush is valid under such circumstances...
I got confused by hibernate documentation that says flush
must be called at the end of a unit of work, before committing the transaction and closing the session
Newer version http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html_single/#d5e976 has example where flush is called in the loop.
Is it ok to call flush not just before committing ? If not, what is the alternative?
Thank you.