I have a scenario in a windows service type app where I need to load up to several thousand entities, perform some business logic and then save them. In regards to session management, this kind of falls outside of the usual session per call that is often discussed. Basically, in my case I certainly don't want one session for (x) thousand entities. The most obvious issue with this would be the memory usage.
In this case, the class that coordinates the work (loading entities and then sending them off to specific classes for processing) needs to be able to have fine grained control over the session. I am contemplating destroying and creating a new session for each entity that needs to be processed. Or, perhaps there is something like calling session.Clear() each time to wipe everything out? The other thing I need is the ability to destroy and re-create a session if an exception occurs. Each entity represents a transaction in that all business logic for that entity needs to succeed or fail. If it fails, I need to rollback, destroy the session, create a new one and then move on to the next entity.
I am even contemplating ignoring the whole repository/dao concept here and just work with the isession directly to keep it simple. However, it would be great to use my existing daos. Perhaps there is another approach where in my coordinating class I can periodically clear or flush the session to release memory and somehow get the new session into the dao?