Announcement Announcement Module
Collapse
No announcement yet.
Transaction propagation problems Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction propagation problems

    sping version 1.1.4

    I have a problem propagating transactions properly. I have a class:
    Code:
    public class CachingJCompAdminService implements JCompAdminService {
       getSchedule () {
           if (!notInCache) {
                init ();
           }
       }
    
        init () {
           dao.readScheule ();
           dao.readMessage ();
        }
    }
    Code:
    dao.readScheule (); will trigger sql like this:
    -- (lp7fs) prepareStatement (select comp_year, openreg_date,        matparta_date, matpartb_date, close_comp   from jcompetition  where comp_year = ?)
    
    while 
    
    dao.readMessage (); will trigger sql like this:
    -- (lp7fs) prepareStatement (select introduction  from jcompetition  where comp_year = ?)

    I configure proxy using the above class as its traget like this:
    Code:
    <bean name="adminJCompService" 
              class="...TransactionProxyFactoryBean">
       &#58;
       &#58;
      <property name="transactionAttributes">
        <props>
           <!-- prop key="*"  >PROPAGATION_REQUIRED</prop -->
           <prop key="init"  >PROPAGATION_REQUIRED</prop>
        </props>
      </property>
    </bean>
    in my connection pool logs I see the folloing:
    Code:
    -- trying to find available connection ...
    -- &#40;lp7fs&#41; connection issued from the pool
    -- &#40;lp7fs&#41; prepareStatement &#40;select comp_year, openreg_date,        matparta_date, matpartb_date, close_comp   from jcompetition  where comp_year = ?&#41;
    -- &#40;lp7fs&#41; close &#40;&#41;
    -- trying to find available connection ...
    -- &#40;lp7fs&#41; connection issued from the pool
    -- &#40;lp7fs&#41; prepareStatement &#40;select introduction  from jcompetition  where comp_year = ?&#41;
    -- &#40;lp7fs&#41; close &#40;&#41;
    because there is no load I am getting the same connection but the fact that init triggered two lookups on the connection pool tells me that there are two different transactions (ro rather no transactions). However, if I change my proxy config to the following:

    Code:
    <bean name="adminJCompService" 
              class="...TransactionProxyFactoryBean">
       &#58;
       &#58;
      <property name="transactionAttributes">
        <props>
           <prop key="*"  >PROPAGATION_REQUIRED</prop>
           <!-- prop key="init"  >PROPAGATION_REQUIRED</prop -->
        </props>
      </property>
    </bean>
    I am seeing this in my db connection logs
    Code:
    -- trying to find available connection ...
    -- &#40;lp7fs&#41; connection issued from the pool
    -- &#40;lp7fs&#41; setAutoCommit &#40;false&#41;
    -- &#40;lp7fs&#41; prepareStatement &#40;select comp_year, openreg_date,        matparta_date, matpartb_date, close_comp   from jcompetition  where comp_year = ?&#41;
    -- &#40;lp7fs&#41; prepareStatement &#40;select introduction  from jcompetition  where comp_year = ?&#41;
    -- &#40;lp7fs&#41; commit &#40;&#41;
    -- &#40;lp7fs&#41; close &#40;&#41;
    which is correct since I have one transaction for both statements

    Code:
    dao.readScheule &#40;&#41;;
    dao.readMessage &#40;&#41;;
    I am sure I messing something in my config, does anyone have an idea of what is wrong?

    Thanks,
    Alex.

  • #2
    The config: <prop key="init" >PROPAGATION_REQUIRED</prop> will not trigger a transaction if getSchedule() is called, even though it calls init(), as the call must be intercepted by the transactional proxy.

    Comment

    Working...
    X