Caching in Hibernate can sometimes lead to Out-Of-Memory exception
if too many objects are being inserted or updated (for example, in a loop).
When so many objects are being updated, hibernate tries to delay their updation in the database by keeping
them in cache for as long as possible, thus leading to an Out-Of-Memory exception.
This can be resolved by calling session.flush() and session.clear() periodically after say every 100 updates.
Alternatively, a property can be added to hibernate.cfg.xml configuration file as follows:
(See line 25 below)