Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Role of hibernate queries in heap dump

I'm JProfiling my application to analyze high CPU usage. CPU usage is 100% (at server) at the time of user login. So started profiling my application.

The below query strings I found in the heap dumps. Not only these 4 queries, there are hundreds of queries like this in the dump.

java.lang.String (0x3262b1) ["/* load com.v4common.shared.beans.transaction.ControlTransaction */ select controltra0_.id as id47_48_, controltra0_.form_transaction_id as form2_47_48_, controltra0_.string_value as string3_47_48_, c"]     129 kB (0 %)
java.lang.String (0x310b2f) ["/* load com.v4common.shared.beans.transaction.ReportTransaction */ select reporttran0_.id as id158_45_, reporttran0_.report_id as report2_158_45_, reporttran0_.norm_id as norm3_158_45_, reporttran0_.d"]     124 kB (0 %)
java.lang.String (0x312222) ["/* load com.v4common.shared.beans.transaction.ReportItemTransaction */ select reportitem0_.id as id160_41_, reportitem0_.report_structure as report2_160_41_, reportitem0_.grid_row_criteria as grid3_16"]     110 kB (0 %)
java.lang.String (0x30c104) ["/* load com.v4common.shared.beans.Reports.EsenderCSReport */ select esendercsr0_.id as id117_36_, esendercsr0_.name as name117_36_, esendercsr0_.report_type as report3_117_36_, esendercsr0_.is_show_pr"]     94,248 bytes (0 %)
java.lang.String (0x30d1dc) ["/* load com.v4common.shared.beans.Reports.ReportStructure */ select reportstru0_.id as id120_35_, reportstru0_.name as name120_35_, reportstru0_.xml as xml120_35_, reportstru0_.esender_format as esend"]     90,736 bytes (0 %)

I'm just logged in the system and I'm not touching the beans at all, still I'm able to see them in the dumps.

Any ideas why those strings are there in the dump?

Or what does that line mean even?

like image 795
Suresh Atta Avatar asked Mar 07 '14 15:03

Suresh Atta


1 Answers

This is normal, these are the Hibernate pre-prepared queries that are prepared at server startup time.

Take for example the ControlTransaction class. Hibernate already knows that will probably need queries to select entities by ID, delete them, etc.

So it generates beforehand a series of SQL prepared statements to do these operations. The comments at the beginning of each query indicate why they where generated.

For example this query was generated to load a ControlTransaction by Id:

/* load com.v4common.shared.beans.transaction.ControlTransaction */ 
select controltra0_.id as id47_48_, controltra0_.form_transaction_id as form2_47_48_, controltra0_.string_value as string3_47_48_, c 

Queries that start with comments of one-to-many or one-to-one, are used for lazy loading, etc. Named queries in JPQL/HQL are also compiled into a SQL query at server startup and the comment identifies which named query originated the SQL query.

Each entity will give rise to several of these queries, depending on the mapping annotations used.

So it's actually normal that these queries are there in the heap at user first login time.

like image 103
Angular University Avatar answered Oct 21 '22 23:10

Angular University