Title: RE: How to Do Transaction with JNDI Datasource and Spring Framework?

Setting up declarative transactions in Spring is really easy if you're Spring wiring stuff.  All you have to do is specify the strategy in the application content file.  Here are the docs:

http://static.springframework.org/spring/docs/1.2.x/reference/transaction.html#d0e5690

So let's say you want to pull a DataSource from JNDI, use it for your SqlMapClient, and use Spring transaction management:

  <!-- Get the DataSource from JNDI -->
  <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>java:comp/env/jdbc/yourDataSourceKey</value>
        </property>
    </bean>
 
  <!-- Setup the sqlmap client -->
  <bean id="sqlMap" class="org.springframework.orm.ibatis.SqlMapFactoryBean">
    <property name="configLocation" value="WEB-INF/sqlmap-config.xml"/>
    <property name="dataSource" ref="dataSource"/>
  </bean>


  <!-- Your DAO wired with the sqlMapClient --> 
  <bean id="someDAOTargetTarget" class="SomeDAO>
       <property name="sqlMapClient" ref="sqlMap"/>
  </bean>

  <!-- Txn wrapper DAO -->
<bean id="someDAO" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="transactionManager" ref="txManager"/>
  <property name="target" ref="someDAOTarget"/>
  <property name="transactionAttributes">
    <props>
      <prop key="insert*">PROPAGATION_REQUIRED,-MyCheckedException</prop>
      <prop key="update*">PROPAGATION_REQUIRED</prop>
      <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
  </property>
</bean>

At this point, you can use the bean named 'someDAO' as you would an instance of SomeDAO.

Cheers,
Chris

-----Original Message-----
From: Mississippi John Hurt [mailto:[EMAIL PROTECTED]]
Sent: Mon 8/21/2006 5:40 PM
To: user-java@ibatis.apache.org
Subject: Re: How to Do Transaction with JNDI Datasource and Spring Framework?

yuck, so we have to configure that in spring.xml?  i looked last time, not
that simple to understand.

On 8/21/06, Paul Benedict <[EMAIL PROTECTED]> wrote:
>
> Spring installs the ibatis ExternalTransactionManager implementation which
> has no-op methods. The methods will do nothing, leaving all the transaction
> management up to the spring proxying.
>
>
> *Mississippi John Hurt <[EMAIL PROTECTED]>* wrote:
>
> Anyone have sample spring, ibatis, config with sample code for this?  I'm
> pretty certain the regular ibatis startTransaction(), endTransaction(),
> commitTransaction() wont work. Thanks.
>
>
> ------------------------------
> Do you Yahoo!?
> Everyone is raving about the all-new Yahoo! Mail.<http://us.rd.yahoo.com/evt=42297/*http://advision.webevents.yahoo.com/mailbeta>
>
>

Reply via email to