iBATIS DataMapper
Added by Clinton Begin, last edited by Clinton Begin on Aug 03, 2009  (view change)

Help out!

Use this page as a sort of "table of contents" for new snippets of documentation and examples. This page will be reviewed periodically and the good stuff will be added to the official documentation.

You make the best author of the documentation, because you are a user of the framework and therefore have a better perspective for what it takes to explain and use iBATIS.

  • Documentation for Feature X
  • Example for Feature Y


A small thing, but I think you should rename the instance variable "sqlMapper" to "sqlSessionFactory" since that's what the SqlSessionFactoryBuilder().build(reader) returns you. It just seems like a good practice in docs to make the instance name more indicative of the type of Class that it represents.

Posted by Rick Reumann at Aug 23, 2009 15:16

In Getting Started paragraph (page 5) of iBATIS 3 User Guide (http://svn.apache.org/repos/asf/ibatis/java/ibatis-3/trunk/doc/en/iBATIS-3-User-Guide.pdf), in place of:

"SqlSessionFactoryBuilder can build a SqlSessionFactory instance from an XML configuration file, of from a custom prepared instance of the Configuration class."

you probably could write:

"SqlSessionFactoryBuilder can build a SqlSessionFactory instance from an XML configuration file, or from a custom prepared instance of the Configuration class."


Posted by Attilio Campedel at Aug 24, 2009 19:30

It's probably a good idea to also show an example of an insert/update or both using the annotation notation as well. Right now the docs only show 'gets.'

Posted by Rick Reumann at Aug 26, 2009 12:37

In reference to nested collections in result maps, I think the docs should mention how to set up the result element when the collection is of a standard java type (String, Integer, etc.) I actually forgot how to set it up myself and didn't see it in the docs, but by trial in error, it's of course real simple:

String username;
List<String> roles;

<resultMap id="userMap" type="User">
     <result property="username" column="username"/>
     <collection property="roles" ofType="String"/>

I know it's simple but still think it should mentioned.

I actually first started out doing the following which worked, but much too verbose, and then had the 'duh' moment when I realized the above was so simple

<resultMap id="userMap" type="User">
     <result property="username" column="username"/>
     <collection property="roles" ofType="String">
         <result javaType="String" column="role_name"/>

Posted by Rick Reumann at Sep 03, 2009 12:42

I wrote up my experience with getting my first iBatis3 project up and running using the spring 3 container. Here it is:

Hope this helps

Posted by David Rosenstark at Sep 09, 2009 06:07

In "Getting Started/Building SqlSessionFactory from XML" it would be better to add the type to the following line:

sqlMapper = new SqlSessionFactoryBuilder().build(reader);

and make it read:

SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);

Posted by Obender at Oct 08, 2009 14:47

The PDF iBATIS-3-User-Guide would benefit from a real PDF type of contents, with each section reference being a hotlink to that section.

Thanks for the fine work on iBATIS and on having documentation.

Posted by Guy Rouillier at Dec 02, 2009 18:25

I thought I read this somewhere but a search of the docs and mail archives didn't turn up anything.

With iBATIS 3, the foreach capability seems to only work with lists or arrays of classes derived from Object, and not with primitive types. I initially tried supplying int[] and iBATIS got horribly confused. The SQL statement that it reported an error on wasn't even the one that was executing.

I switched this to Integer[] and it works fine.

Another aspect of this that some may find confusing is the name of the collection attribute. The guide uses the example collection="list" and then talks about mapping your input into either "array" or "list". If you are using @Param in your mapper Java file, supply that name, and not "list" or "array". For example, here is one of my mapper functions (abbreviated):

List<VwEventSummary> selectCustomerEventSummary(... @Param("eventType") Integer[] eventType);

and here is my foreach clause:

<foreach collection="eventType" item="item" open="(" separator="," close=")">

Posted by Guy Rouillier at Dec 04, 2009 00:56

thanks for a great framework.It would be wonderful if you add how to handle stored procedures in the Docs

Posted by Vishal at Jan 06, 2010 04:34
Site running on a free Atlassian Confluence Open Source Project License granted to OSS. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.5 Build:#811 Jul 25, 2007) - Bug/feature request - Contact Administrators