Announcement Announcement Module
Collapse
No announcement yet.
Pre-bound JDBC connection Found... HibernateTransactionManager Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pre-bound JDBC connection Found... HibernateTransactionManager

    So this has been discussed a million times, sometimes people have found issues with their transaction , sometimes they have had made a mistake of using both HibernateTransactionManager with DataSourceTRansactionManger..and sometimes have used same transaction against two datasources! Before I posted this up here...I made sure we aren't doing any of those obvious mistakes.

    By the way this is whatI am talking about :
    Code:
    org.springframework.transaction.IllegalTransactionStateException: Pre-bound JDBC Connection found! HibernateTransactionManager does not support running within DataSourceTransactionManager if told to manage the DataSource itself. It is recommended to use a single HibernateTransactionManager for all transactions on a single DataSource, no matter whether Hibernate or JDBC access. 
    at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:426) 
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:350) 
    at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:262) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:102) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) 
    at $Proxy207.getMyPersonalData(Unknown Source)
    We notice running into this issue after we find this in our Weblogic logs :

    Code:
    <1359911323638> <BEA-001153> <Forcibly releasing inactive connection "weblogic.jdbc.wrapper.PoolConnection_oracle_jdbc_driver_T4CConnection@1c59665" back into the connection pool "my_Pool", currently reserved by: java.lang.Exception 
    at weblogic.jdbc.common.internal.ConnectionEnv.setup(ConnectionEnv.java:308) 
    at weblogic.common.resourcepool.ResourcePoolImpl.reserveResource(ResourcePoolImpl.java:314) 
    at weblogic.common.resourcepool.ResourcePoolImpl.reserveResource(ResourcePoolImpl.java:292) 
    at weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:425) 
    at weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:316) 
    at weblogic.jdbc.common.internal.ConnectionPoolManager.reserve(ConnectionPoolManager.java:93) 
    at weblogic.jdbc.common.internal.ConnectionPoolManager.reserve(ConnectionPoolManager.java:106) 
    at weblogic.jdbc.pool.Driver.connect(Driver.java:149) 
    at weblogic.jdbc.jts.Driver.getNonTxConnection(Driver.java:642) 
    at weblogic.jdbc.jts.Driver.connect(Driver.java:124) 
    at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:338) 
    at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81) 
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:421) 
    at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144) 
    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139) 
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1538) 
    at org.hibernate.loader.Loader.doQuery(Loader.java:661) 
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) 
    at org.hibernate.loader.Loader.loadEntity(Loader.java:1851) 
    at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48) 
    at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42) 
    at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3038) 
    at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395) 
    at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375) 
    at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139) 
    at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:98) 
    at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878) 
    at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:836) 
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:66) 
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111) 
    at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:140) 
    at com.business.bom.MYJob$$EnhancerByCGLIB$$36de44fa.getStartedTime(<generated>) 
    at ... blha blha 
    
    com.my.apps.ui.publishedReport.MyPublishedReportController.getMyJobView(MyPublishedReportController.java:231) 
    at at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:857) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:475) 
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:430) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    So we know this comes from the following code in Spring :
    Code:
    tx.getDataSource != null and  ! tx.getDataSource.issynchronisedwithTransaction {
    
    throw this prebound jdbc connection found!.....
    }
    Well after immense google searching i have still not been able to recreate this issue or know the cause of this issue...
    My suspicion is
    1)Weblogic is taking away the connection before a transaction is completed and that releases the transaction but it does not give hibernate and spring a chance to do its cleanup process and hence never set the isSyncrnoized with transaction as false (Not sure how to recreate to validate this suspiscion)

    2) We have a PROPOGATION_REQUIRED even for get* methods....They are not PROPOGATION_REQUIRED,read-only

    3) We have the hibernateTransaction injected at the DAO as well as the Service layer..


    Any good soul has suggestion on what my app is doing wrong?

    * This issue never happens in our development environment. Happens only in production! Also once we recycle the cluster insatnce it goes away for few days, but only to come back.
    Last edited by trader_stewie; Feb 10th, 2013, 01:09 AM.

  • #2
    Anyone, anybody?
    Even if you can help me answer why would Hibernate not release a acquired connection , well it seems Hibernate is sometimes unable to release an acquired connection when its obtained beyond the scope of the transaction ie. while preparing the view bean some of the lazy initialized objects are obtained outside the scope of the method that was transactional , but then Hibernate forgot to release that connection!

    Comment


    • #3
      So i upgraded my spring version to 2.5.6 and this is what i see now :

      Code:
      org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed: 
      at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:599) 
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:377) 
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101) 
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) 
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) 
      at $Proxy154.getTrainDetail(Unknown Source) 
      at com.uprr.apps.lda.ui.tacticalplanselection.TacticalPlanSelectionController.reDirect(TacticalPlanSelectionController.java:212) 
      at sun.reflect.GeneratedMethodAccessor11615.invoke(Unknown Source) 
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
      at java.lang.reflect.Method.invoke(Method.java:597) 
      at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473) 
      at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410) 
      at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153) 
      at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48) 
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875) 
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809) 
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571) 
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:512) 
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) 
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:821) 
      at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) 
      at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292) 
      at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:27) 
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:43) 
      at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) 
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:43) 
      at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) 
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:43) 
      at com.uprr.apps.lda.ui.LDAWicketFilter.doFilter(LDAWicketFilter.java:59) 
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496) 
      at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180) 
      at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086) 
      at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406) 
      at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201) 
      at weblogic.work.ExecuteThread.run(ExecuteThread.java:173) 
      org.hibernate.TransactionException: JDBC begin failed: 
      at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:68) 
      at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326) 
      at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:558) 
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:377) 
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101) 
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) 
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) 
      at $Proxy154.getDetail(Unknown Source) 
      at com.uprr.apps.lda.ui.tacticalplanselection.TacticalPlanSelectionController.reDirect(TacticalPlanSelectionController.java:212) 
      at sun.reflect.GeneratedMethodAccessor11615.invoke(Unknown Source) 
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
      at java.lang.reflect.Method.invoke(Method.java:597) 
      at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473) 
      at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410) 
      at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153) 
      at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48) 
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875) 
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809) 
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571) 
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:512) 
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) 
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:821) 
      at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) 
      at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292) 
      at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:27) 
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:43) 
      at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) 
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:43) 
      at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) 
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:43) 
      at com.uprr.apps.lda.ui.LDAWicketFilter.doFilter(LDAWicketFilter.java:59) 
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496) 
      at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180) 
      at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086) 
      at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406) 
      at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201) 
      at weblogic.work.ExecuteThread.run(ExecuteThread.java:173) 
      java.sql.SQLException: Connection has already been closed. 
      at weblogic.jdbc.wrapper.PoolConnection.checkConnection(PoolConnection.java:55) 
      at weblogic.jdbc.wrapper.Connection.preInvocationHandler(Connection.java:92) 
      at weblogic.jdbc.wrapper.PoolConnection_oracle_jdbc_driver_T4CConnection.getAutoCommit(Unknown Source) 
      at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57) 
      at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1327) 
      at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:558) 
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:377) 
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101) 
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) 
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) 
      at $Proxy154.getDetail(Unknown Source)

      Comment

      Working...
      X