When you call session.close(), the session is effectively done. The first level cache is discarded and the session can't be reopened.
Session.Disconnect will release the underlying db connection; however, the first level cache remains. You can reconnect the session (I think the function is actually called session.reconnect), and continue to use the underlying cache. Objects that were attached to the session prior to the disconnect remain attached on the reconnect.
Disconnect can be used when you are waiting for user input. Pull your object out of the database, disconnect the session, allow the user to manipulate the object, reconnect the session, then persist. You should look into optimistic locking if you are going to use this method.
Another way to accomlish this is to create a new session and reattach the object to the new cache with the Lock or Update functions (optimistic locking applies here as well).
Regards,
Trisk
|