You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Mississippi John Hurt <jo...@gmail.com> on 2006/08/22 01:10:10 UTC
How to Do Transaction with JNDI Datasource and Spring Framework?
Anyone have sample spring, ibatis, config with sample code for this? I'm
pretty certain the regular ibatis startTransaction(), endTransaction(),
commitTransaction() wont work. Thanks.
Re: How to Do Transaction with JNDI Datasource and Spring
Framework?
Posted by Chris Lamey <cl...@localmatters.com>.
The JavaDoc for the Spring SqlMapClientFactoryBean says:
"The default ExternalTransactionConfig is appropriate if there is
external transaction management that the SqlMapClient should participate
in: be it Spring transaction management, EJB CMT or plain JTA. This
should be the typical scenario. If there is no active transaction,
SqlMapClient operations will execute SQL statements
non-transactionally."
Here:
http://static.springframework.org/spring/docs/2.0-m3/api/org/springframework/orm/ibatis/SqlMapClientFactoryBean.html#setTransactionConfigClass(java.lang.Class)
Spring assumes that if you're using the SqlMapClientFactoryBean you want
to be able to Spring-wire everything, which means you don't want to use
the iBATIS txn manager.
Cheers,
Chris
On Tue, 2006-08-22 at 08:43 -0700, Mississippi John Hurt wrote:
> Is it possible to use an eternal JNDI datasource but with the internal
> Transaction Manager?
>
> On 8/21/06, Paul Benedict <pa...@yahoo.com> wrote:
> No. If you use the SqlMapClientDao template, Spring does it
> all for you. All you will have to do is specify the master
> sqlmap configuration file in spring and inject it into your
> dao.
>
>
> Mississippi John Hurt <johnhurt@gmail.com > wrote:
> 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 <pa...@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.
>
>
>
>
>
> ______________________________________________________________
> Get your own web address for just $1.99/1st yr. We'll help.
> Yahoo! Small Business.
>
>
Re: How to Do Transaction with JNDI Datasource and Spring Framework?
Posted by Mississippi John Hurt <jo...@gmail.com>.
Is it possible to use an eternal JNDI datasource but with the internal
Transaction Manager?
On 8/21/06, Paul Benedict <pa...@yahoo.com> wrote:
>
> No. If you use the SqlMapClientDao template, Spring does it all for you.
> All you will have to do is specify the master sqlmap configuration file in
> spring and inject it into your dao.
>
>
> *Mississippi John Hurt <jo...@gmail.com>* wrote:
>
> 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>
> >
>
>
> ------------------------------
> Get your own web address for just $1.99/1st yr. We'll help. Yahoo! Small
> Business<http://us.rd.yahoo.com/evt=41244/*http://smallbusiness.yahoo.com/>.
>
>
>
RE: How to Do Transaction with JNDI Datasource and Spring Framework?
Posted by Chris Lamey <cl...@localmatters.com>.
Two things:
1) The name of the SomeDAO bean should be 'someDAOTarget', not 'someDAOTargetTarget'.
2) Since transactions are managed externally to iBATIS, there's no need for explicit transaction handling in Java code. In fact, if you do have startTransaction, commitTransaction, etc. in Java, those calls will be ignored because iBATIS is expecting the external manager to handle them.
Also, if you use the iBATIS DAOs and not your own, the sqlMap and dataSource sets are a little different. Take a look at the Spring docs for iBATIS, they've got great examples in xml and java.
Cheers,
Chris
-----Original Message-----
From: Chris Lamey [mailto:clamey@localmatters.com]
Sent: Mon 8/21/2006 7:32 PM
To: user-java@ibatis.apache.org; user-java@ibatis.apache.org
Subject: 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: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 <pa...@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 <jo...@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>
>
>
RE: How to Do Transaction with JNDI Datasource and Spring Framework?
Posted by Chris Lamey <cl...@localmatters.com>.
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: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 <pa...@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 <jo...@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>
>
>
Re: How to Do Transaction with JNDI Datasource and Spring Framework?
Posted by Paul Benedict <pa...@yahoo.com>.
No. If you use the SqlMapClientDao template, Spring does it all for you. All you will have to do is specify the master sqlmap configuration file in spring and inject it into your dao.
Mississippi John Hurt <jo...@gmail.com> wrote: 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.
---------------------------------
Get your own web address for just $1.99/1st yr. We'll help. Yahoo! Small Business.
Re: How to Do Transaction with JNDI Datasource and Spring Framework?
Posted by Mississippi John Hurt <jo...@gmail.com>.
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 <pa...@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 <jo...@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>
>
>
Re: How to Do Transaction with JNDI Datasource and Spring Framework?
Posted by Paul Benedict <pa...@yahoo.com>.
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 <jo...@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.