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 Abdullah Kauchali <ab...@isanusi.com> on 2005/08/04 13:00:26 UTC

Ibatis and Spring Framework

Can someone who has experience with the Spring Framework please help me 
explain briefly what advantages
it could afford /along with/ the use of Ibatis.

What is it that the Spring offers that IBatis does not?

(I know that Spring is multi-facetted, it does AOP stuff etc - but I am 
asking specificially about
its JDBC "wrapping" capabilities).  Anything there that I should be 
looking at?

Any comments would be greatly appreciated,

Kind regards

Abdullah

RE: Ibatis and Spring Framework

Posted by John Hurst <jb...@attglobal.net>.
Hi,

I use iBATIS with Spring.  In fact I learned about iBATIS via Spring; I
think the two together work very well.

In addition to Richard's comments, I would add:

  - Common configuration mechanism across your whole project, and separation
of configuration from your code.

With Spring, your DAOs can be provided with what they need via dependency
injection.  You put for example a setDataSource() in your class, and you can
configure Spring to wire up the DataSource at runtime.  This is incredibly
powerful.

  - The SqlMapClientDaoSupport provides a great base class for DAOs to make
use of Spring facilities, such as transparent transaction control.  It
already has the setters necessary to configure DataSource or SqlMapClient.
It also provides the SqlMapClientTemplate, a smart way to do operations
requiring resources.

For example the iBATIS developer guide example

public void updateItemDescription(String itemId, String newDescription)
throws SQLException {
  try {
    sqlMap.startTransaction();
    Item item = (Item) sqlMap.queryForObject ("getItem", itemId);
    item.setDescription (newDescription);
    sqlMap.update ("updateItem", item);
    sqlMap.commitTransaction ();
  } finally {
    sqlMap.endTransaction ();
  }
}

Could look like this with Spring:

public void updateDescription(String itemId, String newDescription) {
  Item item = (Item) getSqlMapClientTemplate().queryForObject("getItem",
itemId);
  Item.setDescription(newDescription);
  getSqlMapClientTemplate().update("updateItem", item);
}

Many fully transactional DAO methods become one-liners with Spring.

The iBATIS API is very clean; the advantage of the Spring XxxTemplate
classes becomes all the more clearer with an API like raw JDBC.

Regards

John Hurst


> -----Original Message-----
> From: rich oates [mailto:oates1@gmail.com]
> Sent: Friday, 5 August 2005 07:18
> To: user-java@ibatis.apache.org
> Subject: Re: Ibatis and Spring Framework
> 
> The Spring JDBC wrapper offers at least the following:
> 
> - a further abstraction away from iBatis (which is useful if you wish
> to change the underlying persistence framework in the future)
> 
> - common data access exceptions (i.e. the iBatis exceptions are mapped
> to spring exceptions. Again, useful if you want to reduce dependency
> on iBatis).
> 
> There are other benefits, especially when the rest of what Spring
> offers is taken into account, e.g. transparent transaction handling.
> 
> I recommend having a look at chapter 11 of the Spring reference
> documentation.
> 
> regards
> richard


Re: Ibatis and Spring Framework

Posted by rich oates <oa...@gmail.com>.
The Spring JDBC wrapper offers at least the following:

- a further abstraction away from iBatis (which is useful if you wish
to change the underlying persistence framework in the future)

- common data access exceptions (i.e. the iBatis exceptions are mapped
to spring exceptions. Again, useful if you want to reduce dependency
on iBatis).

There are other benefits, especially when the rest of what Spring
offers is taken into account, e.g. transparent transaction handling.

I recommend having a look at chapter 11 of the Spring reference documentation.

regards
richard