ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Lamey" <cla...@localmatters.com>
Subject RE: How to Do Transaction with JNDI Datasource and Spring Framework?
Date Tue, 22 Aug 2006 01:32:41 GMT
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


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">
  <!-- 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"/> 

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

  <!-- 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">
      <prop key="insert*">PROPAGATION_REQUIRED,-MyCheckedException</prop>
      <prop key="update*">PROPAGATION_REQUIRED</prop>
      <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>

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


-----Original Message-----
From: Mississippi John Hurt [mailto:johnhurt@gmail.com]
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 <paul4christ79@yahoo.com> 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 <johnhurt@gmail.com>* 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>

View raw message