Disable query plan execution of HQL in hibernate 5.2.11final at the time of application loading


Disable query plan execution of HQL in hibernate 5.2.11final at the time of application loading.

is responsible for increase in memory


You need to provide more context to your problem.

Is the memory issue due to the fact that you have many NamedQuery defined which Hibernate needs to parse and store so that you can alter use without reparsing them?


Yes exactly this is what I want


yes I have many NamedQuery in my application and the memory consumption drastically increased after migrating to Hibernate 5.2.11FINAL from 4.1.9.Final


Upgrading to a newer version can solve many problems. Hibernate 4.1 is rather old, and many things have been improved since 4.x.


I have upgraded to 5.2.11Final and the memory consumption issue is occurring in 5.2.11


Try to profile it and see why it takes so much memory.

And when you say a lot of memory, how much is it taking? And how many named queries do you have?


hi vlad,
I did the profiling and observed that org.loader.plan.build.internal* package is consuming more memory and i compared it with older version (4.1.9) in which the above mention package is not present.

And number of named queries i have is 660 and number of entities are 450.

I am running batches using spring batch previously it required 512MB heap but now after migrating to hibernate 5.2.11 it requies 1024MB heap memory
please find the profiling screenshot for hibernate 5.2.11.


But in that diagram, the Query plan only takes 16 MB. Anyway, if it does not leak memory, just add sufficient RAM.

Nowadays, notebooks have 16 GB of RAM and servers way more than that. A 1 GB JVM is not out of the ordinary for an enterprise application.

The plan cache is just a cache. You can tune it to cache less and save memory, but it will cost you in terms of extra CUP processing.


Hi Vlad,

Thanks for your input and view will decrease the quert plan cache as you mentioned in the below thread


Sure thing. You can configure these two properties to adjust the query plan cache size.

  1. hibernate.query.plan_cache_max_size
  2. hibernate.query.plan_parameter_metadata_max_size


Is there any way to disable this query plan cache?


If you set the hibernate.query.plan_cache_max_size to 0, it will disable the plan cache, but it’s not a good idea because the performance of JPQL and Criteria API will not be very good.


hibernate.batch_fetch_style =DYNAMIC fixed my issue