Some batch processes have input data which isn't modified during that process, but which may be updated in other use cases. However, when the batch process session is flushed, those unmodifiable objects are checked for needed updates. This can lead to a significant performace degradation when dealing with large volumes of objects.
It would be of great help to be able to inform the session at creation time which entities are read-only for that session. When an object is added to the persistenceContext or its status changed, if its status is MANAGED and its class is one of the configured as read-only, the status is changed to READ_ONLY.
In addition to the less cpu time consumed, it frees the memory used by the snapshot copy used for dirty checking.
This code is implemented as a decorator for the PersistenceContext and attached in this issue.
3.2.5.GA, Database independent