Monday, April 19, 2010

Hibernate CacheMode.IGNORE option

Recently, I have ran into a hibernate related issue in our production system. We have a nightly batch program that reads a lot of rows from one table, then does some conversion and writes to a file. It brings 5000 rows in chunk, still we saw the nightly program took the server down with outOfMemory error when processing large number of rows.

After some investigation, I have found that the program brings out all the data in one session. Hibernate is holding all the objects in its session until session is closed. As a result, the GC can't clear any previous chunk of object from memory.

Since the we are reading the data for readonly purpose, we set the CacheMode.IGNORE on the Query object. It prevents Hibernate to hold the reference of the objects in it's session.

Here is snippet of the code.

Query qry = session.createQuery(query).setCacheMode(CacheMode.IGNORE);

2 comments:

  1. Merkur Gold Strike Safety Razor - FEBCASINO
    Merkur's Gold Strike Safety Razor, Merkur Platinum Edge Plated Finish, microtouch solo titanium German, Gold-Plated, https://febcasino.com/review/merit-casino/ Satin Chrome Finish. Merkur has wooricasinos.info a more aggressive 도레미시디 출장샵 looking, poormansguidetocasinogambling.com

    ReplyDelete