java - hibernate 查询在堆转储中的作用

标签 java hibernate jakarta-ee heap-memory jprofiler

我是 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-manyone-to-one注释开头的查询,用于延迟加载等。JPQL/HQL中的命名查询是还在服务器启动时编译成 SQL 查询,注释标识哪个命名查询发起了 SQL 查询。

每个实体都会产生几个这样的查询,具体取决于所使用的映射注释。

所以在用户首次登录时,这些查询在堆中实际上是正常的。

关于java - hibernate 查询在堆转储中的作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22254273/

相关文章:

java - java 解释器如何获取 main 函数,即使它被放置在内部类中?

java - jsoup 传输了多少字节

mysql - 用于获取表列数的 hibernate 查询

java - 从 Java 6 SE 迁移到 Java 6 EE

java - ARCore ArSceneView 捕获位图

javax.el.PropertyNotFoundException : Property 'toArray' not found on type org. hibernate.collection.internal.PersistentSet

java - 即使在 timeToLiveSeconds 和/或 timeToIdleSeconds 之后,Ehcache 也不会从缓存中删除元素

java - 当调用 openSession 并且无法建立与 DB 的连接时,Hibernate 不会抛出异常

Java EE - 具有许多 Web 应用程序的应用程序服务器的 JVM

java - 从另一只耳朵访问耳朵里的 jar 里的类