Actually, transactions don't quite work that way.
Basically, if you have any object attached to a session and it's state changes then those changes will be persisted to the database when a flush occurs.
Normally flushing occurs on an as-needed basis; this could be when you commit a transaction or it could be when you execute a query to ensure that the query results match the data in memory.
You've said explicitly that you only want changes to be flushed on commit of a transaction, but that doesn't mean that changes made to persistent objects outside the transaction won't be tracked - they'll still be flushed when the next flush occurs unless you evict them from the session.
The transaction you've created ensures that all the SQL statements that are executed are all handled in a database transaction. This allows you to make sure that all actions against the database can be atomic for the NHibernate transaction, although the actual database transaction will not start until the first action against the database happens (ie when the first flush occurs).
Does that make sense?
Cheers,
Symon.
|