异常出现时,Hibernate CreateNativeQuery不会关闭连接

时间:2015-03-18 10:09:39

标签: java hibernate jpa connection database-connection

我面临一个与休眠CreateNativeQuery相关的问题。

我已使用createNativeQuery执行查询并返回resultList。如果由于查询不正确或原因而导致查询执行失败,则会引发异常,并且不会关闭实体管理器使用的连接。为什么连接没有关闭消息到达?

如果我使用createQuery方法,我只面对异常,连接由实体管理器正确关闭。

这背后的原因是什么?

我的代码是

return em.createNativeQuery(queryToExecute).getResultList();

如果我使用createNativeQuery方法,为什么连接未关闭?

日志详情

2015-03-13 11:21:40,504 WARN  [org.jboss.jca.adapters.jdbc.WrappedConnection] Closing a statement you left open, please do your own housekeeping: java.lang.Throwable: STACKTRACE
at org.jboss.jca.adapters.jdbc.WrappedConnection.registerStatement(WrappedConnection.java:1672) at org.jboss.jca.adapters.jdbc.WrappedStatement.<init>(WrappedStatement.java:105)
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.<init>(WrappedPreparedStatement.java:69)
at org.jboss.jca.adapters.jdbc.jdk6.WrappedPreparedStatementJDK6.<init>(WrappedPreparedStatementJDK6.java:52)
at org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6.wrapPreparedStatement(WrappedConnectionJDK6.java:79)
at org.jboss.jca.adapters.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:404)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:161)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:159)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1854)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1831)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1811)
at org.hibernate.loader.Loader.doQuery(Loader.java:899)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
at org.hibernate.loader.Loader.doList(Loader.java:2516)
at org.hibernate.loader.Loader.doList(Loader.java:2502)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2332)
at org.hibernate.loader.Loader.list(Loader.java:2327)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338)
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1826)
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:231)
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:157)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:264)

2015-03-13 11:21:40,506 INFO  [org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager] IJ000100: Closing a connection for you. Please close them yourself: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@7bc7c07d: java.lang.Throwable: STACKTRACE 
at org.jboss.jca.core.connectionmanager.ccm.CachedConnectionManagerImpl.registerConnection(CachedConnectionManagerImpl.java:269)
at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:495)
at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:139)
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:292)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:56)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:161)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:159)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1854)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1831)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1811)

提前致谢。

0 个答案:

没有答案