iBatis / iBator

iBatis / iBator

iBATIS發展已經有7年以上的成果。iBATIS 3 完全重寫了code,現在的iBATIS 3 版本與最初的 iBATIS 有了很大改變。iBATIS 3中引入了很多Java 5 中的先進特性。iBATIS 3 包含了新的設計工具用於幫助用戶創建資料庫驅動的應用程序。iBATIS 3 繼續保持了它一貫的優良傳榮,在現在的 iBATIS 3 中,仍然不需要依賴第三方的 Package。與之前的 iBATIS 版本比較起來,iBATIS 3使用更簡單,功能更強大。


iBATIS Schema Migration System

iBATIS 3 中引入了一個新的功能,稱之為:iBATIS Schema Migration System(也可以稱之為 iBATIS Migrations for short),這個強大的工具靈感來源於 Rails 的 Migrations 功能。BATIS Schema Migration System 用於提供給用於一個方便的資料庫修改管理解決方案。工具允許多個用戶對資料庫進行類似增量修改的方式,只改動需要修改的那部分表結構,而不是重新初始化整個資料庫表。iBATIS 3 功能將會成為一個亮點。

官方教學手冊, http://ibatis.apache.org/docs/tools/ibator/

ibator for Eclipse Plug-in

Ibator is a code generator for iBATIS. Ibator will introspect a database table (or many tables) and will generate iBATIS artifacts that can be used to access the table(s). This abates some of the initial nuisance of setting up objects and configuration files to interact with database tables. Ibator seeks to make a major impact on the large percentage of database operations that are simple CRUD (Create, Retrieve, Update, Delete). You will still need to hand code SQL and objects for custom queries, or stored procedures.

Ibator will generate:

  • SqlMap XML Files
  • Java Classes to match the primary key and fields of the table(s)
  • DAO Classes that use the above objects (optional)



  1. Create new java project
  2. Add [Apache ibator configuration xml file]
  3. Add Libs
    1. ibator
    2. JDBC driver
  4. setting xml context
    1.  JDBC driver class name
    2. URL
    3. UserName
    4. Password
  5. add XML element - ClassDriverPath = [your postgresql jdbc .jar]

Running Ibator from Java with an XML Configuration File

The following code sample shows how to call Ibator from Java. It does not show exception handling, but that should be obvious from the compiler errors :)

   List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("ibatorConfig.xml");
IbatorConfigurationParser cp = new IbatorConfigurationParser(warnings);
IbatorConfiguration config = cp.parseIbatorConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
Ibator ibator = new Ibator(config, callback, warnings);


  • Configuration file properties may be passed to the parser as a parameter on the IbatorConfigurationParser constructor. If not passed explicitly, the JVM system properties will be searched for the value of configuration file properties. For example, the property generated.source.dir can be accessed in the Ibator configuration file with the escape sequence ${generated.source.dir}
  • If a property is specified in the configuration file and is not resolved, then the escaped property string will be passed "as is" into the generated code.


子網頁 (2): Example Schema Migration System