HHH000387 休眠警告是什么意思?

发布于 2024-12-25 03:59:28 字数 118 浏览 0 评论 0原文

我刚刚更新到 Hibernate 4.0,并在我的日志文件中看到警告消息:

HHH000387:ResultSet 的语句未注册

。这是什么意思?我应该担心吗?

I have just updated to Hibernate 4.0 and am seeing the warning message :

HHH000387: ResultSet's statement was not registered

in my log files. What does this mean, and should I be worried?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

橙味迷妹 2025-01-01 03:59:28

我不会太担心。无论如何,API 用户似乎无法避免此消息。日志记录是在 org.hibernate.engine.jdbc.internal.JdbcResourceRegistryImpl 中完成的。根据 文档

JdbcResourceRegistry的主要功能是确保资源
清理干净。

简单看一下代码就知道,这样的消息在两种情况下会被记录:

  1. ResultSet是通过register方法注册的,statement没有注册。
  2. ResultSet 通过release-method 释放,statement 未注册。

I would not worry too much. In any case it looks like it is not in API's users hands to avoid this message. Logging is done in the org.hibernate.engine.jdbc.internal.JdbcResourceRegistryImpl. According documentation:

The main function of a JdbcResourceRegistry is to make sure resources
get cleaned up.

Short look to the code tells, that such a message is logged in two situations:

  1. ResultSet is registered via register-method, and statement is not registered.
  2. ResultSet is released via release-method and statement is not registered.
花海 2025-01-01 03:59:28

查看引发此错误的 JdbcResourceRegistryImpl 类的源代码,我个人认为将其记录在 WARN 级别是过度的;它最多应该是 INFO,除非有一种方法可以将所有语句隐式注册为 Hibernate/framework 配置的一部分。

我不清楚为什么应该注册 Statement,但如果这只是 Hibernate 内部工作的问题,那么定期警告 API 用户这就是一个错误,对吗?

Looking at the source for the JdbcResourceRegistryImpl class that throws this error, I personally think having it log at WARN level is excessive; it should be INFO at most, unless there's a way to have all Statements implicitly registered as part of a Hibernate/framework configuration.

It's not clear to me why a Statement should be registered, but if it's only a concern of the inner workings of Hibernate then routinely warning API users about it is a bug, right?

送舟行 2025-01-01 03:59:28

此日志消息表明 ResultSet.getStatement() 未返回最初要求创建 ResultSetStatement。 (它也可能表明内存泄漏。)使用 JDBC 包装器时可能会发生这种情况,因为有两个 Statement 对象:包装器/装饰器和底层 Statement

在我的项目中,我有自己的 JDBC 包装器用于测试。我通过确保 getStatement() 返回原始 Statement 代理(不是新代理),而不是委托给底层 ResultSet(这将返回底层 Statement)。

任何产生类似警告的 JDBC 包装器都可能使用类似的修复方法。 (类似的问题和修复可能适用于方法 Statement.getConnection()。)

顺便说一下,这里有一个关于此日志记录的错误报告:https://hibernate.atlassian.net/browse/HHH-8210

This log message is a sign that ResultSet.getStatement() doesn't return the Statement which was originally asked to create the ResultSet. (It may also indicate a memory leak.) This can happen when using a JDBC wrapper, because there are two Statement objects: a wrapper/decorator and the underlying Statement.

In my project, I have my own JDBC wrapper for testing. I fixed this warning in my ResultSet wrapper by ensuring that getStatement() returns the original Statement proxy (not a new proxy), rather than delegating to the underlying ResultSet (which would return the underlying Statement).

Any JDBC wrapper which is producing similar warnings could probably use a similar fix. (A similar problem and fix may apply to the method Statement.getConnection().)

By the way, there is a bug report for this logging here: https://hibernate.atlassian.net/browse/HHH-8210

合约呢 2025-01-01 03:59:28

你配置了连接池吗?我也收到同样的警告。但是如果我在我的 Maven 依赖项中添加了 c3p0 并在 hibernate.cfg.xml 中正确配置了它。警告消失。

Did you configured connection pool? I've got the same warning. But if I added c3p0 in my maven dependency and get it correctly configured in hibernate.cfg.xml. The warning disappears.

一桥轻雨一伞开 2025-01-01 03:59:28

就我而言,此警告表明存在巨大的性能泄漏!
我有带有 @oneToOne 映射的 hibernate POJO 对象。对于一张表,它工作正常并且没有警告:它向 MySQl 服务器发送一个请求以获取所有记录,然后向每个连接表发送一个请求。
对于 POJO,我收到此错误(当未找到 @oneToOne 时):它发送一个初始请求以获取所有对象的列表,然后每次发送针对每条记录的映射表的新请求。

假设我的测试数据库中有 2000 条记录。和 3 个 @oneToOne 映射表。

在良好的情况下,它会发送 1 个获取列表的请求和 3 个获取映射表的请求。

如果出现警告,它会发送 1 个获取列表的初始请求。然后发送 3 个请求以获取数据库中 2000 条记录中每条记录的映射信息!因此,每个用户每次调用 @Controller (Spring MVC) 都会有 1999*3=5997 个额外请求。

当 Web 应用程序和 MySQL 服务器位于同一服务器上时,我没有注意到这一点。

In my case this warning was an indicator of huge performance leak!
I have hibernate POJO objects with @oneToOne mapping. For one table it works fine and no warnings: it sends one request to MySQl server for getting all the records and then for one requests for each joined table.
For POJO where I'm getting this error (when no @oneToOne found): it sends one initial request for getting a list of all objects and then every time send new and new requests for mapped tables for each record.

So, let's say I have 2000 records in my test DB. And 3 @oneToOne mapped tables.

In a good case, it sends 1 request for getting a list and 3 requests for getting mapped tables.

In the case of a warning, it sends 1 initial request for getting list. Then send 3 requests for getting mapped info for each of 2000 records in DB! So 1999*3=5997 additional requests for each user for each call the @Controller (Spring MVC).

I hadn't noticed it while the web application and MySQL server were on the same server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文