Our application is built on one-shot Sessions (ie, we close the Session after each CRUD operation). We’re trying to use long Sessions, but the dirty tracking is giving us problems. Since the code was built assuming that changes would only be persisted by explicit calls to update(), our calculations are not as careful as they now need to be.
So, can we turn off the automatic state tracking while keeping the entity cache and cascading updates and deletes?
You can’t turn off managed entity handling. You can however call Session.clear() after every read operation if you want that, or use a StatelessSession if that fits your work style better, though note that it comes with a slightly different programming model in terms of cascading.
You will have to clear the persistence context at some point if you don’t want managed flushing. StatelessSession will just implicitly clear the persistence context after every operation.