我是 JProfiling我的应用程序分析高 CPU 使用率。用户登录时 CPU 使用率为 100%(在服务器)。所以开始分析我的应用程序。
我在堆转储中找到的以下查询字符串。不仅这 4 个查询,转储中还有数百个这样的查询。
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 %)
我刚刚登录系统,我根本没有接触 bean,但我仍然能够在转储中看到它们。
知道为什么这些字符串会出现在转储中吗?
或者那条线是什么意思?
最佳答案
这是正常的,这些是在服务器启动时准备的 Hibernate 预准备查询。
以 ControlTransaction
类为例。 Hibernate 已经知道可能需要查询来按 ID 选择实体、删除它们等。
所以它预先生成了一系列SQL准备语句来完成这些操作。每个查询开头的注释说明了它们生成的原因。
例如,生成此查询以通过 Id 加载 ControlTransaction:
/* 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
以one-to-many
或one-to-one
注释开头的查询,用于延迟加载等。JPQL/HQL中的命名查询是还在服务器启动时编译成 SQL 查询,注释标识哪个命名查询发起了 SQL 查询。
每个实体都会产生几个这样的查询,具体取决于所使用的映射注释。
所以在用户首次登录时,这些查询在堆中实际上是正常的。
关于java - hibernate 查询在堆转储中的作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22254273/