mysql show war,为什么在此发布“SHOW WARNINGS”查询? (JPA /休眠/ MySQL的)

We are refactoring the persistence layer of a Java application from JDBC Template to JPA/Hibernate.

I am profiling the SQL statements being issued to the database and I see "SHOW WARNINGS" is issued many, many times. According to JProfiler the "SHOW WARNINGS" is accounting for a considerable amount of 'inherent time'.

What could cause SHOW WARNINGS to be issued so frequently?

This SHOW WARNINGS was NOT previously issued when using Jdbc Template.

Below is the part of our stack relevant to persistence. The only change here is the introduction of JPA/Hibernate.

JPA / Hibernate: 4.3.6

MySQL driver: 5.1.33

MySQL database: 5.6.20

JDBC Connection Pool: HikariCP-2.3.2

EDIT: Here's a sample stack trace of when SHOW WARNINGS is issued.

com.mysql.jdbc.StatementImpl.getWarnings()

com.zaxxer.hikari.proxy.PreparedStatementJavassistProxy.getWarnings()

org.hibernate.jpa.internal.QueryImpl.getSingleResult()

com.mysema.query.jpa.impl.AbstractJPAQuery.getSingleResult(javax.persistence.Query)

com.mysema.query.jpa.impl.AbstractJPAQuery.uniqueResult()

com.mysema.query.jpa.impl.AbstractJPAQuery.uniqueResult(com.mysema.query.types.Expression)

org.springframework.aop.framework.JdkDynamicAopProxy.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[ ])

com.sun.proxy.$Proxy115.findOne(com.mysema.query.types.Predicate)

解决方案

This is WHY show warnings is being issued:

org.hibernate.engine.jdbc.spi.SqlExceptionHelper.handleAndClearWarnings() is calling com.mysql.jdbc.StatementImpl.getWarnings().

A comment in the Hibernate source code says:

"See HHH-9174. Statement#getWarnings can be an expensive call for

many JDBC libs. Don't do it unless the log level would actually allow

a warning to be logged."

I upped the logging level on logback.xml on "org.hibernate" to ERROR. Profiling shows SHOW WARNINGS query is NO LONGER being issued.

This has made a marginal improvement in performance.

I would appreciate any input as to whether it is actually a good idea to disable SHOW WARNINGS here.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值