Domanda

How to calculate the size in bytes (not number rows) of the resultset returned by a criteria query? We receive a Out of Memory Exception and on analysis of heapdump we found the org.hibernate.impl.sessionimpl object is the most bloated object. We have one very complex query that is executed multiple times and returns >4000 rows with 150 columns in each row. We want to find out if this is the offending query by trying to get the size of the resultset?

Meanwhile we are trying session.clear (will this work) after the results set is fetched. Are there any other steps I can follow to reduce sessionimpl size in memory? Thanks

È stato utile?

Soluzione

You can follow Calculate size of Object in Java answer.
But if you have memory problem most probably better solutions can be:

  1. Maximize memory heap
  2. Use a ScrollableResults to avoid all memory issues

I prefer solution number 2 because it is definitive; the first one can still cause memory problem.

Altri suggerimenti

you can try use Hibernate Statistics When Optimizing Queries

Refer to the link above which has very good explanation on how to use stats in hibernate.

Just FYI.

SessionFactory sessionFactory = getSessionFactoryForApplication();
Statistics stats = sessionFactory.getStatistics();
stats.setStatisticsEnabled(true); 

Hope this helps to find the reason for OM error in your code.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top