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

  • TransactionManager for Hibernate and plain JDBC access fails


    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.

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

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

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

    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.

    my.ChangesNotPersistedException&#58; Hibernate Exception&#58;
            at my.UserServiceImpl.createUser&#40;;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.
      //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;;
        catch &#40;Throwable ex&#41; &#123;
          // target invocation exception
          doCloseTransactionAfterThrowing&#40;txInfo, ex&#41;;
          throw ex;