Announcement Announcement Module
Collapse
No announcement yet.
TransactionManager for Hibernate and plain JDBC access fails Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • TransactionManager for Hibernate and plain JDBC access fails

    Hello,


    First a little bit about my environment.

    I use the spring-framework 1.1 and have a problem with the transaction management.

    I would be able to use both Hibernate and plain JDBC code for the database acess. Both (Hibernate, and JDBC access) are encapsulated in an own written persistence manager. This persistence manager could throw three exceptions ChangesDoNotPersistException, PersistenceInitException and PersistenceException.

    Now I want to use the spring transaction manager. I use AOP funcionallity with the TransactionInterceptor.

    Code:
    <bean id="TransactionInterceptor"
            class="my.TransactionInterceptor">
            <property name="transactionManager">
                <ref bean="TransactionManager"/>
            </property>
            <property name="transactionAttributeSource">
                <value>my.PojoService.*User=PROPAGATION_REQUIRED
                </value>
            </property>
        </bean>
    
        <bean id="TransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource">
                <ref bean="AwareTransactionDataSource"/>
            </property>
        </bean>
    
        <bean id="AwareTransactionDataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
            <property name="targetDataSource">
                <ref bean="DataSource"/>
            </property>
        </bean>
    
        <bean id="DataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName">
                <value>ThinDBPoolDataSource</value>
            </property>
        </bean>
    
        <bean id="my.UserPojoService" class="org.springframework.aop.framework.ProxyFactoryBean">
            <property name="proxyInterfaces">
                <value>my.IService</value>
            </property>
            <property name="interceptorNames">
                <list>
                    <value>TransactionPointcutAdvisor</value>
                    <value>PojoService</value>
                </list>
            </property>
        </bean>
    The persistence manager has a static method (getInstance). And I try to invoke this by this:

    Code:
    <bean id="PojoService" class="my.PojoService">
            <property name="persistenceManager">
                <ref bean="PersistenceManager"/>
            </property>
            <property name="baseLogger">
                <ref bean="BaseLogger"/>
            </property>
        </bean>
    
         <bean id="PersistenceManager" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
            <property name="staticMethod">
                <value>my.PersistenceManagerFactory.getInstance</value>
            </property>
        </bean>
    so persistence manager is usable for PojoService.

    During runtime:
    When transaction beans are created on startup I get a lot of these messages:

    Code:
    INFO; ; 2004-09-15 14&#58;31&#58;52,778; org.springframework.transaction.interceptor.MethodMapTransactionAttributeSource;Message&#58; Adding transactional method &#91;public void my.PojoService.createUser&#40;my.Data data&#41; throws my.PersistenceException,my.PersistenceInitException,my.ChangesNotPersistedException&#93; with attribute &#91;PROPAGATION_REQUIRED,ISOLATION_DEFAULT&#93;;
    so I think the Transaction manager is configured well and tries to catch those Exceptions.

    But the result is that the Exceptions are not catched and the application did a crash.

    Code:
    my.ChangesNotPersistedException&#58; Hibernate Exception&#58;
            at my.HibernatePersister.store&#40;HibernatePersister.java&#58;124&#41;
            at my.PersistenceManagerImpl.store&#40;PersistenceManagerImpl.java&#58;208&#41;
            at my.UserServiceImpl.createUser&#40;UserServiceImpl.java&#58;96&#41;
    ...
    Is something wrong with my configuration?
    Without transaction manager directly over the persistenc manager everything runs well.
    Did I have to use metadata compilation in my case?
    How could I resolve this problem.

    Thanks for reply

  • #2
    so I think the Transaction manager is configured well and tries to catch those Exceptions.
    TransactionInterceptor does catch Throwable (checked and unchecked exceptions) but it rethrows them so as your application knows about them.
    Code:
      //From TransactionInterceptor source
        Object retVal = null;
        try &#123;
          // This is an around advice.
          // Invoke the next interceptor in the chain.
          // This will normally result in a target object being invoked.
          retVal = invocation.proceed&#40;&#41;;
        &#125;
        catch &#40;Throwable ex&#41; &#123;
          // target invocation exception
          doCloseTransactionAfterThrowing&#40;txInfo, ex&#41;;
          throw ex;
        &#125;

    Comment

    Working...
    X