- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们有一个使用 Hibernate 查询 Oracle 数据库的 Grails 应用程序。
通过诸如 SQL Developer 之类的工具直接针对数据库运行一个相对简单的条件查询,最坏情况下只需要二十分之一秒,而现在则需要几分之一秒到 30 秒完成。
将 logSql
设置为 true
并确认生成的 SQL 是高性能的(解释计划成本约为 100,执行时间为 10-30 毫秒),我们在通过将其日志记录级别设置为 TRACE
来更深入地了解 Hibernate 在做什么。
这是我们在标准输出中看到的:
******************** START HIBERNATE QUERY TRACE *****************
start time (millis): 1400772671767
2014-05-22 11:31:11,767 [http-bio-8080-exec-5] DEBUG transaction.JDBCTransaction - begin
2014-05-22 11:31:11,767 [http-bio-8080-exec-5] DEBUG transaction.JDBCTransaction - current autocommit status: true
2014-05-22 11:31:11,767 [http-bio-8080-exec-5] DEBUG transaction.JDBCTransaction - disabling autocommit
2014-05-22 11:31:11,767 [http-bio-8080-exec-5] TRACE jdbc.JDBCContext - after transaction begin
2014-05-22 11:31:11,770 [http-bio-8080-exec-5] TRACE loader.Loader - querySpaces is [REDACTED]
2014-05-22 11:31:11,770 [http-bio-8080-exec-5] TRACE loader.Loader - transformer=org.hibernate.transform.RootEntityResultTransformer returnTypes=[ REDACTED ] returnClasses=[ class REDACTED ]
2014-05-22 11:31:11,770 [http-bio-8080-exec-5] DEBUG jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2014-05-22 11:31:11,771 [http-bio-8080-exec-5] DEBUG hibernate.SQL - select REDACTED
2014-05-22 11:31:11,771 [http-bio-8080-exec-5] TRACE jdbc.AbstractBatcher - preparing statement
2014-05-22 11:31:11,771 [http-bio-8080-exec-5] TRACE sql.BasicBinder - binding parameter [1] as REDACTED
2014-05-22 11:31:11,771 [http-bio-8080-exec-5] TRACE sql.BasicBinder - binding parameter [2] as REDACTED
2014-05-22 11:31:11,772 [http-bio-8080-exec-5] TRACE sql.BasicBinder - binding parameter [3] as REDACTED
2014-05-22 11:31:11,772 [http-bio-8080-exec-5] TRACE loader.Loader - Bound [4] parameters total
2014-05-22 11:31:12,323 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564865835008
2014-05-22 11:31:12,324 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:12,324 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:12,324 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564865839104
2014-05-22 11:31:12,324 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:12,324 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:14,331 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564874059776
2014-05-22 11:31:14,331 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:14,331 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:14,331 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564874059777
2014-05-22 11:31:14,331 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:14,332 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:16,339 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564882284544
2014-05-22 11:31:16,339 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:16,339 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:16,339 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564882284545
2014-05-22 11:31:16,340 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:16,340 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:18,348 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564890513408
2014-05-22 11:31:18,348 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:18,348 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:18,348 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564890513409
2014-05-22 11:31:18,349 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:18,349 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:20,356 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564898738176
2014-05-22 11:31:20,356 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:20,356 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:20,356 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564898738177
2014-05-22 11:31:20,357 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:20,357 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:22,364 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564906958848
2014-05-22 11:31:22,364 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:22,364 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:22,364 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564906962944
2014-05-22 11:31:22,364 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:22,364 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:24,373 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564915191808
2014-05-22 11:31:24,373 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:24,373 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:24,373 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564915191809
2014-05-22 11:31:24,374 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:24,374 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:26,379 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564923408384
2014-05-22 11:31:26,379 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:26,379 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:26,379 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564923408385
2014-05-22 11:31:26,379 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:26,379 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:28,387 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564931633152
2014-05-22 11:31:28,387 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:28,387 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:28,387 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564931633153
2014-05-22 11:31:28,387 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:28,388 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:30,395 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564939857920
2014-05-22 11:31:30,396 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:30,396 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:30,396 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564939862016
2014-05-22 11:31:30,396 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:30,396 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:32,403 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564948082688
2014-05-22 11:31:32,404 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:32,404 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:32,404 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564948086784
2014-05-22 11:31:32,404 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:32,404 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:34,408 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564956295168
2014-05-22 11:31:34,409 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:34,409 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:34,409 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564956299264
2014-05-22 11:31:34,409 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:34,409 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:36,416 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564964519936
2014-05-22 11:31:36,416 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:36,416 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:36,416 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564964519937
2014-05-22 11:31:36,416 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:36,417 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:38,421 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564972732416
2014-05-22 11:31:38,422 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:38,422 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:38,422 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564972736512
2014-05-22 11:31:38,422 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:38,422 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:40,428 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564980953088
2014-05-22 11:31:40,429 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:40,429 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:40,429 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564980957184
2014-05-22 11:31:40,429 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:40,429 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:42,436 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564989177856
2014-05-22 11:31:42,437 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:42,437 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:42,437 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564989181952
2014-05-22 11:31:42,437 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:42,437 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:44,441 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564997390336
2014-05-22 11:31:44,442 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:44,442 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:44,442 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737564997394432
2014-05-22 11:31:44,442 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:44,442 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:46,449 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737565005615104
2014-05-22 11:31:46,450 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:46,450 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:46,450 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737565005619200
2014-05-22 11:31:46,450 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:46,450 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:48,458 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737565013839872
2014-05-22 11:31:48,458 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:48,458 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:48,458 [http-bio-8080-exec-10] DEBUG impl.SessionImpl - opened session at timestamp: 5737565013843968
2014-05-22 11:31:48,458 [http-bio-8080-exec-10] TRACE impl.SessionImpl - closing session
2014-05-22 11:31:48,458 [http-bio-8080-exec-10] TRACE jdbc.ConnectionManager - connection already null in cleanup : no action
2014-05-22 11:31:49,985 [http-bio-8080-exec-5] DEBUG jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
2014-05-22 11:31:49,986 [http-bio-8080-exec-5] TRACE loader.Loader - processing result set
2014-05-22 11:31:49,986 [http-bio-8080-exec-5] TRACE loader.Loader - done processing result set (0 rows)
2014-05-22 11:31:49,986 [http-bio-8080-exec-5] DEBUG jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
2014-05-22 11:31:49,986 [http-bio-8080-exec-5] DEBUG jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2014-05-22 11:31:49,986 [http-bio-8080-exec-5] TRACE jdbc.AbstractBatcher - closing statement
2014-05-22 11:31:49,986 [http-bio-8080-exec-5] TRACE loader.Loader - total objects hydrated: 0
2014-05-22 11:31:49,986 [http-bio-8080-exec-5] DEBUG engine.StatefulPersistenceContext - initializing non-lazy collections
2014-05-22 11:31:49,986 [http-bio-8080-exec-5] TRACE loader.Loader - transformer=org.hibernate.transform.RootEntityResultTransformer returnTypes=[ REDACTED ] returnClasses=[ class REDACTED ]
2014-05-22 11:31:49,987 [http-bio-8080-exec-5] DEBUG transaction.JDBCTransaction - commit
2014-05-22 11:31:49,987 [http-bio-8080-exec-5] TRACE impl.SessionImpl - automatically flushing session
2014-05-22 11:31:49,987 [http-bio-8080-exec-5] TRACE def.AbstractFlushingEventListener - flushing session
2014-05-22 11:31:49,987 [http-bio-8080-exec-5] REDACTED
2014-05-22 11:31:49,989 [http-bio-8080-exec-5] TRACE jdbc.ConnectionManager - registering flush begin
2014-05-22 11:31:49,989 [http-bio-8080-exec-5] TRACE jdbc.ConnectionManager - registering flush end
2014-05-22 11:31:49,989 [http-bio-8080-exec-5] TRACE def.AbstractFlushingEventListener - post flush
2014-05-22 11:31:49,989 [http-bio-8080-exec-5] TRACE jdbc.JDBCContext - before transaction completion
2014-05-22 11:31:49,989 [http-bio-8080-exec-5] TRACE impl.SessionImpl - before transaction completion
2014-05-22 11:31:49,991 [http-bio-8080-exec-5] DEBUG transaction.JDBCTransaction - re-enabling autocommit
2014-05-22 11:31:49,991 [http-bio-8080-exec-5] DEBUG transaction.JDBCTransaction - committed JDBC Connection
2014-05-22 11:31:49,991 [http-bio-8080-exec-5] TRACE jdbc.JDBCContext - after transaction completion
2014-05-22 11:31:49,991 [http-bio-8080-exec-5] DEBUG jdbc.ConnectionManager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
2014-05-22 11:31:49,992 [http-bio-8080-exec-5] TRACE impl.SessionImpl - after transaction completion
2014-05-22 11:31:49,992 [http-bio-8080-exec-5] DEBUG impl.SessionImpl - disconnecting session
2014-05-22 11:31:49,992 [http-bio-8080-exec-5] TRACE jdbc.ConnectionManager - performing cleanup
2014-05-22 11:31:49,992 [http-bio-8080-exec-5] DEBUG jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2014-05-22 11:31:49,992 [http-bio-8080-exec-5] TRACE jdbc.JDBCContext - after transaction completion
2014-05-22 11:31:49,992 [http-bio-8080-exec-5] DEBUG jdbc.ConnectionManager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
2014-05-22 11:31:49,992 [http-bio-8080-exec-5] TRACE impl.SessionImpl - after transaction completion
end time (millis): 1400772709992
difference: 38.225 seconds
******************* END HIBERNATE QUERY TRACE ********************
让我提醒您注意什么引起了我们的注意 - 大约每 2 秒重复的六行 - opened session
然后 closing session
然后 connection已经为空
,在一毫秒的跨度内完成了两次。
Hibernate 每隔 2 秒左右打开并立即关闭 2 个 session ?我的解释正确吗?什么情况下它会做这样的事情?
DataSource.groovy
中的数据源配置是基本的:
dataSource_REDACTED {
driverClassName = 'oracle.jdbc.OracleDriver'
dialect = 'org.hibernate.dialect.Oracle10gDialect'
url = 'jdbc:oracle:thin:@REDACTED:1521/REDACTED'
username = 'REDACTED'
password = 'REDACTED'
pooled = true
properties {
maxActive = 20
minIdle = 1
initialSize = 10
testOnBorrow = true
testWhileIdle = true
validationQuery = "SELECT 1 FROM DUAL"
}
}
没有 properties{}
阻塞在那里,所以无论使用空闲超时等属性的默认值。
同一个文件中还有一个hibernate配置:
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
正如我之前所说,我正在执行的条件查询非常简单:
withTransaction {
List<MyAwesomeClass> awesomeThings = withCriteria {
between("importantTime", startDate, endDate)
eq("importantField", targetValue)
}
}
条件查询是从 Controller 直接调用的 Grails 域类中的方法运行的,而不是事务服务,因此我将其包装在 withTransaction
中。
总之,简而言之,这是怎么回事?为什么在某事(不确定是什么)发生并且查询实际执行之前, session 会如此困惑?尝试创建连接时是否与数据库本身的可用性有关?
最佳答案
这行引起了我的注意:
transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
TRACE jdbc.JDBCContext - after autocommit
根据 Hibernate docs :
ON_CLOSE - is essentially the legacy behavior described above. The Hibernate session obtains a connection when it first needs to perform some JDBC access and holds unto that connection until the session is closed.
on_close - says to use ConnectionReleaseMode.ON_CLOSE. This setting is left for backwards compatibility, but its use is highly discouraged.
JPA 确实允许您执行查询,即使您没有在事务中运行,但我不建议您使用此设置。
我总是将所有 Hibernate 代码包装在一个事务中,对于只读操作,我选择 readOnly=true 标志。
每个线程似乎连续打开和关闭两个 session ,如果那是因为您运行两个连续的查询,您可以通过在同一 session 中运行它们来优化它。
因为您打开和关闭 session 的速度如此之快,所以您也在打开和关闭 JDBC 连接,并且您的设置不包含任何连接池。除非您使用连接池,否则创建和销毁连接的成本将非常高。
查看我的 benchmark on how connection pooling可以显着提高您的应用程序性能。
所以:
关于oracle - 当 session 在没有连接的情况下打开和关闭时,Hibernate 查询停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23773876/
我是 Java 新手,这是我的代码, if( a.name == b.name && a.displayname == b.displayname && a.linknam
在下面的场景中,我有一个 bool 值。根据结果,我调用完全相同的函数,唯一的区别是参数的数量。 var myBoolean = ... if (myBoolean) { retrieve
我是一名研究 C++ 的 C 开发人员: 我是否正确理解如果我抛出异常然后堆栈将展开直到找到第一个异常处理程序?是否可以在不展开的情况下在任何 throw 上打开调试器(即不离开声明它的范围或任何更高
在修复庞大代码库中的错误时,我观察到一个奇怪的情况,其中引用的动态类型从原始 Derived 类型更改为 Base 类型!我提供了最少的代码来解释问题: struct Base { // some
我正在尝试用 C# 扩展给定的代码,但由于缺乏编程经验,我有点陷入困境。 使用 Visual Studio 社区,我尝试通过控制台读出 CPU 核心温度。该代码使用开关/外壳来查找传感器的特定名称(即
这可能是一个哲学问题。 假设您正在向页面发出 AJAX 请求(这是使用 Prototype): new Ajax.Request('target.asp', { method:"post", pa
我有以下 HTML 代码,我无法在所有浏览器中正常工作: 我试图在移动到
我对 Swift 很陌生。我如何从 addPin 函数中检索注释并能够在我的 addLocation 操作 (buttonPressed) 中使用它。我正在尝试使用压力触摸在 map 上添加图钉,在两
我设置了一个详细 View ,我是否有几个 Nib 文件根据在 Root View Controller 的表中选择的项目来加载。 我发现,对于 Nibs 的类,永远不会调用 viewDidUnloa
我需要动态访问 json 文件并使用以下代码。在本例中,“bpicsel”和“temp”是变量。最终结果类似于“data[0].extit1” var title="data["+bpicsel+"]
我需要使用第三方 WCF 服务。我已经在我的证书存储中配置了所需的证书,但是在调用 WCF 服务时出现以下异常。 向 https://XXXX.com/AHSharedServices/Custome
在几个 SO 答案(1、2)中,建议如果存在冲突则不应触发 INSERT 触发器,ON CONFLICT DO NOTHING 在触发语句中。也许我理解错了,但在我的实验中似乎并非如此。 这是我的 S
如果进行修改,则会给出org.hibernate.NonUniqueObjectException。在我的 BidderBO 类(class)中 @Override @Transactional(pr
我使用 indexOf() 方法来精细地查找数组中的对象。 直到此刻我查了一些资料,发现代码应该无法正常工作。 我在reducer中尝试了上面的代码,它成功了 let tmp = state.find
假设我有以下表格: CREATE TABLE Game ( GameID INT UNSIGNED NOT NULL, GameType TINYINT UNSIGNED NOT NU
代码: Alamofire.request(URL(string: imageUrl)!).downloadProgress(closure: { (progress) in
我是一名优秀的程序员,十分优秀!