iBATIS DataMapper
Added by Kai Grabfelder, last edited by Justin Koke on Jan 18, 2010  (view change)
Labels: 
(None)


Useful Information

iBATIS 3 is currently in development. Once iBATIS 3 is released the information from this page will be moved to the official documentation. Until iBATIS 3 is released feel free to download the sources directly from the source repository http://svn.apache.org/repos/asf/ibatis/java/ibatis-3/trunk/

getting started

During this tutorial we will create a small maven project with a testcase showing the basic functionality of iBATIS 3 using the in memory h2 database.

create maven project

Create a new maven project using the quickstart archetype

mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=org.apache.ibatis -DartifactId=ibatis3-tutorial

This will create the following directory layout:

└───src
   ├───main
   │   └───java
   │       └───org
   │           └───apache
   │               └───ibatis
   └───test
   └───java
   └───org
   └───apache
   └───ibatis

Add the ibatis and h2 dependencies to the pom.xml and change the default sorce version to 1.5 so it looks like:

/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.ibatis</groupId>
   <artifactId>ibatis3-tutorial</artifactId>
   <packaging>jar</packaging>
   <version>1.0-SNAPSHOT</version>
   <name>ibatis3-tutorial</name>
   <url>http://maven.apache.org</url>
   <build>
   <plugins>
   <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>2.0.2</version>
   <configuration>
   <source>1.5</source>
   <target>1.5</target>
   <encoding>UTF-8</encoding>
   </configuration>
   </plugin>
   </plugins>
   </build>
   <dependencies>
   <dependency>
   <groupId>org.apache.ibatis</groupId>
   <artifactId>ibatis-3-core</artifactId>
   <version>3.0-SNAPSHOT</version>
   </dependency>
   <dependency>
   <groupId>com.h2database</groupId>
   <artifactId>h2</artifactId>
   <version>1.1.113</version>
   </dependency>
   <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.6</version>
   <scope>test</scope>
   </dependency>
   </dependencies>
   </project>

Run a maven build to see if the dependencies can be properly resolved:

[INFO] ------------------------------------------------------------------------
   [INFO] BUILD SUCCESSFUL
   [INFO] ------------------------------------------------------------------------
   [INFO] Total time: 5 seconds
   [INFO] Finished at: Sun May 31 20:43:08 CEST 2009
   [INFO] Final Memory: 11M/20M
   [INFO] ------------------------------------------------------------------------

database schema

In this example we will assume that we have an existing database structure that we want query and manipulate using iBATIS. For this tutorial we will use the following database structure described in

/src/test/resources/database.ddl
CREATE TABLE PERSON(
   PER_ID NUMBER (5, 0) NOT NULL,
   PER_FIRST_NAME VARCHAR (40) NOT NULL,
   PER_LAST_NAME VARCHAR (40) NOT NULL,
   PER_BIRTH_DATE DATETIME ,
   PER_WEIGHT_KG NUMBER (4, 2) NOT NULL,
   PER_HEIGHT_M NUMBER (4, 2) NOT NULL,
   PRIMARY KEY (PER_ID)
   );
   );

I take it the iBatis 3 snapshots and betas are not in the Maven central repo? Is there an Atlassian repo that it's in?

Posted by George Thiruva at Sep 03, 2009 11:04

Get a copy of ibatis3 sources, compile and install using maven. It gives you ibatis in your local repository.

svn co http://svn.apache.org/repos/asf/ibatis/java/ibatis-3/tags/java_release_3.0.0-200_beta_3/
cd java_release_3.0.0-200_beta_3
mvn clean install

you may want skip junit test in case of build failure or comment out the test which are fails.

Posted by Bala Raman at Oct 04, 2009 05:12

Hey,

I am trying to do a mvn clean compile and it is throwing up errors ! Hence i am not able to install it in my local repo ! Also, i want to do some changes on it. Any ideas what i am missing?

The error is pasted below.

[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).

Project ID: null:ibatis-3-core:jar:null

Reason: Cannot find parent: org.apache.ibatis:ibatis-3 for project: null:ibatis-3-core:jar:null for project null:ibatis-3-core:jar:null

[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.reactor.MavenExecutionException: Cannot find parent: org.apache.ibatis:ibatis-3 for project: null:ibatis-3-core:jar:null for project null:ibatis-3-core:jar:null
at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:404)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:272)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.project.ProjectBuildingException: Cannot find parent: org.apache.ibatis:ibatis-3 for project: null:ibatis-3-core:jar:null for project null:ibatis-3-core:jar:null
at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1396)
at org.apache.maven.project.DefaultMavenProjectBuilder.buildInternal(DefaultMavenProjectBuilder.java:823)
at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromSourceFileInternal(DefaultMavenProjectBuilder.java:508)
at org.apache.maven.project.DefaultMavenProjectBuilder.build(DefaultMavenProjectBuilder.java:200)
at org.apache.maven.DefaultMaven.getProject(DefaultMaven.java:604)
at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:487)
at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:391)
... 12 more
Caused by: org.apache.maven.project.ProjectBuildingException: POM 'org.apache.ibatis:ibatis-3' not found in repository: Unable to download the artifact from any repository

org.apache.ibatis:ibatis-3:pom:3.0-SNAPSHOT

from the specified remote repositories:
archiva.snapshots (http://repo.ad.corp.expertcity.com:8080/archiva/repository/snapshots),
Ibatis repo (http://svn.apache.org/repos/asf/ibatis/trunk/java/ibatis-3/),
archiva.ibiblio (http://repo.ad.corp.expertcity.com:8080/archiva/repository/ibiblio),
internal (http://repo.ad.corp.expertcity.com:8080/archiva/repository/internal),
spring-milestone (http://s3.amazonaws.com/maven.springframework.org/milestone),
archiva.default (http://repo.ad.corp.expertcity.com:8080/archiva/repository/internal)

for project org.apache.ibatis:ibatis-3

Posted by Praveen Krishnan at Oct 21, 2009 15:34

Never mind, Issue resolved, Did not get the parent pom.

Posted by Praveen Krishnan at Oct 21, 2009 17:56

The article has been finished?
Where did you query database?
And the svn url is not correct now,please check it and correct it:
http://svn.apache.org/repos/asf/ibatis/trunk/java/ibatis-3/

Posted by chenshu at Nov 06, 2009 03:08
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