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

  • IllegalTransactionStateException: Pre-bound JDBC connection

    Hi!

    I've web application (spring 1.1.4, hiberante 2.1.8, tomcat 5.5.8 ) which had been working correctly for about the month. For last few days I get exception:
    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.
    
    org.springframework.orm.hibernate.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:367)
    org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:272)
    org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:202)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:49)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
    org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:632)
    What can be the reason and why this problem appear after more than month of correct work?

    Thanks for help,
    Artur Wronski

  • #2
    Can you post the datasource/transaction parts of your application context.

    Comment


    • #3
      data source and transaction parts

      it's rather simple...:


      Code:
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
          <property name="driverClassName"><value>org.postgresql.Driver</value></property>
          <property name="url"><value>jdbc&#58;postgresql&#58;//127.0.0.1&#58;5432/mydb</value></property>
          <property name="username"><value>username</value></property>
          <property name="password"><value>password</value></property>
        </bean>
      
        <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
      	<property name="mappingResources">
      	  <list>
      	    <value>domain/hbm/User.hbm.xml</value>
      	  </list>
      	</property>
      	<property name="hibernateProperties">
      	  <value>classpath&#58;hibernate.properties</value>
      	</property>
      	<property name="dataSource">
      	  <ref bean="dataSource"/>
      	</property>
        </bean>
      
      
        <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
          <property name="sessionFactory"><ref bean="sessionFactory"/></property>
        </bean>
      
        <bean id="userDao" class="domain.UserDao">
      	<property name="sessionFactory"><ref bean="sessionFactory"/></property>
        </bean>
      
      
        <bean id="managerServiceTarget" class="domain.ManagerService">
      	<property name="userDao"><ref bean="userDao"/></property>
        </bean>
      
        <bean id="managerService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
          <property name="transactionManager"><ref bean="transactionManager"/></property>
          <property name="target"><ref bean="managerServiceTarget"/></property>
          <property name="proxyTargetClass"><value>true</value></property>
          <property name="transactionAttributes">
            <props>
              <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
      	<prop key="*">PROPAGATION_REQUIRED</prop>
            </props>
          </property>
        </bean>
      After tomcat restart everything works correct now. So maybe this is some bug in spring, webserver or hibernate?

      Thanks for help,
      Artur

      Comment


      • #4
        So... ???

        Did anybody identify what was happening in this case? Any improvements about it in Spring 2.0?

        Who's guilty?

        Comment


        • #5
          I guess, the problem might be occurring because, direct JDBC calls might be being made in the code ie. there might be a mix of delcrataive asnd programmatic transaction. When using JDBC along with a transaction manager, the connection should not be obtained from the datasource directly using the getConnection() method as per Spring specification. You should use DataSourceUtils.getConnection() passing it the datasource as follows:
          Connection con = DataSourceUtils.getConnection(dataSource).
          This is required to allow the relevant TransactionManager to keep track of the connection usage, and apply transaction management as necessary.

          Comment


          • #6
            if i could chime in with my 2 cents...

            i had this happen in my TestCases because there were two transaction managers getting loaded by autowire byname. once i corrected this to ensure only one tx mgr was used, the problem was solved. so perhaps there are two tx mgrs being loaded into your controller or app context (i know theres only one in the config above, but thought id mention it for others).

            - tobes

            Comment


            • #7
              I'm suddenly having problems with this. I do not use any direct JDBC access (hence no getConnection()), and have got only one transaction manager in my Spring context (singleton).

              I have the feeling that this problem started to surface with Hibernate 3.2.2 and did not happen (or was hidden somehow) with Hibernate 3.2.1.

              a_wronski, could you solve your problem?

              Regards,

              Andreas

              Comment


              • #8
                I'm not sure you'll get a response from the original author, "Last Activity: 12-03-2005 08:28 AM". To try and solve your problem it would be useful to see the applicationContext.xml, the unit test you are running and maybe even the code that is causing problematic.

                Comment


                • #9
                  can you post some code of your service class !!!

                  Comment


                  • #10
                    Prevent more than one transaction managers from being loaded

                    @tobysaville

                    I, too, have this message occuring, sometimes now that I added some Dao loaded by autowire on name.

                    For example, the problem never occured when I only had:

                    @Autowired
                    protected WebpageDirectoryDao webpageDirectoryDao;

                    But now that I have:

                    @Autowired
                    protected WebpageDirectoryDao webpageDirectoryDao;
                    @Autowired
                    protected WebpageDao webpageDao;

                    the problem sometimes occurs

                    Could you explain a bit how you prevented more than one transaction managers from being loaded ?

                    Thanks !

                    Stephane



                    Originally posted by tobysaville View Post
                    if i could chime in with my 2 cents...

                    i had this happen in my TestCases because there were two transaction managers getting loaded by autowire byname. once i corrected this to ensure only one tx mgr was used, the problem was solved. so perhaps there are two tx mgrs being loaded into your controller or app context (i know theres only one in the config above, but thought id mention it for others).

                    - tobes

                    Comment

                    Working...
                    X