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


#1

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

org.hibernate.loader.plan.exec.query.internal.SelectStatementBuilder.java
is responsible for increase in memory


#2

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?


#3

Yes exactly this is what I want


#4

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


#5

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


#6

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


#7

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?


#8

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.


#9

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.


#10

Hi Vlad,

Thanks for your input and view will decrease the quert plan cache as you mentioned in the below thread
https://forum.hibernate.org/viewtopic.php?f=1&t=1044019


#11

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

#12

Is there any way to disable this query plan cache?


#13

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.


#15

hibernate.batch_fetch_style =DYNAMIC fixed my issue