ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Poitras Christian <Christian.Poit...@ircm.qc.ca>
Subject RE: beginner spring+ibatis help
Date Mon, 30 Jun 2008 11:48:52 GMT

First I'd make my SqlMap class extends SqlMapClientDaoSupport from Spring since it will relieve
you of writing a try-catch block.

    public List<Product> getProductList() throws DataAccessException {
        logger.info("Getting products! (iBatis)");

        List<Product> allProducts = queryForList("selectAllProducts");
        return allProducts;

Second, I'd handle transaction in a service class.

Public class ProductService {
    ProductDao productDao;

    -- Transaction managed by Spring.
    public List<Product> getProductList() throws DataAccessException {
        return productDao.getProductList();

This works if you use annotations in Spring. (See annotations in section 3.11 and transaction
in section 9.5)


-----Original Message-----
From: Daniel Guido [mailto:dguido@gmail.com]
Sent: Friday, June 27, 2008 4:50 PM
To: user-java@ibatis.apache.org
Subject: beginner spring+ibatis help

I'm a student and my grasp of JSP/J2EE, iBatis, and Spring is a little iffy. I'm attempting
to learn all of them as part of a project and I'd appreciate any help you could offer me (and
to save time, yes, I've read the developer's guide pdf).

I followed the Spring tutorial to create their little inventory management demo-app. It works
fine with JDBC and HSQL and I mostly understand what's going on. The URL for that tutorial
is here:

Now I'm trying to replace the JDBC DAO with an iBatis DAO. I think I've got everything put
together correctly, but my ProductDao (the parent class to my SqlMapProductDao) has a method:
public List<Product> getProductList(); It was created in this step of the
tutorial: http://static.springframework.org/docs/Spring-MVC-step-by-step/part5.html#step5.4

How do I create an equivalent function in the SqlMapProductDao? I made a sql map that looks
like this (my columns and properties match, no need for result maps):
<select id="selectAllProducts" resultMap="ProductResult">
    select * from products

The following is _completely_ wrong but at least shows what I'd like it to do:

    public List<Product> getProductList() throws DataAccessException {
      logger.info("Getting products! (iBatis)");

      try {
          List<Product> allProducts =
          return allProducts;
      catch (SQLException ex) {}

based off this:

Can anyone help? I can post more of the source I'm working with if you think it will help.

Dan Guido

View raw message