My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Generator  
An introduction to the code generation tool for MyBatis
Updated Jan 3, 2011 by jeffgbut...@gmail.com

Introduction to MyBatis Generator

MyBatis Generator is a code generator for MyBatis. MyBatis Generator will introspect a database table (or many tables) and will generate MyBatis 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. MyBatis Generator 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.

MyBatis Generator will generate:

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

MyBatis Generator can run as a standalone JAR file, as an Ant task, a Maven plugin, or an Eclipse plugin.

Get MyBatis Generator

Google Code

MyBatis generator is available from the MyBatis site at http://code.google.com/p/mybatis/downloads/list?can=3&q=Product%3DGenerator The bundle includes documentation for the generator.

Maven

MyBatis generator is available in the Maven central repository at:

Grouporg.mybatis.generator
Artifactmybatis-generator-maven-plugin
Version1.3.1

Eclipse

MyBatis generator is available as an Eclipse plugin and includes the extra capability of merging generated Java files as databases evolve. Documentation for MyBatis generator is integrated into the Eclipse help system. To install the Eclipse plugin, configure a new Eclipse install repository and point to this location:

http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/

The plugin is currently developed and compiled with Eclipse 3.6.1 (Helios SR1) and has not been tested on earlier releases.

Comment by liangyyy...@gmail.com, Jun 11, 2010

The ibator 1.2.1 can not used for mybatis 3,0.what time update?

Comment by mm1983...@gmail.com, Jun 21, 2010

I also have this question. ibator is an greate tool. When will update this tool to support the 3.?

Comment by ymer.and...@gmail.com, Jun 22, 2010

I'm starting a new ibatis 3.0 project now. I tried building MyBatis? Generator from source but have not figured out how to make it generate for 3.0.

Is the MyBatis? Generator working for ibatis 3.0?

Comment by ymer.and...@gmail.com, Jun 22, 2010

To make it work for 3. I had to change context to: <ibatorContext id="context1" targetRuntime="MyBatis3">

and <daoGenerator .. .. .. type="MAPPER"/>

Comment by project member hob...@gmail.com, Jun 29, 2010

> (December 22, 2008) MyBatis? Generator version 1.2.1 is release With the last update 1.5 years ago, is this project dying or dead? I cant find a single code example on the web which works with mybatis 3, and my hope was this generator would give me a starting point.

Comment by yuanhu...@gmail.com, Jul 27, 2010

Why not use the template(freemark or velocity)? If that,user can modify the template to grenerate code by self,just like Jboss Hibernate Tools , ect.

Comment by mhafizyu...@gmail.com, Oct 6, 2010

What is current web path for MyBatis? Generator ?

Comment by gfrancis1, Oct 8, 2010

This is ridiculous - where is the Generator download? MyBatis? contributors take note - you are losing past and prospective users by the day... that is, if you care anymore.

Comment by 22361...@qq.com, Oct 10, 2010

I have the same question about it What time can ibator support the mybatis 3.0

Comment by zsum...@gmail.com, Oct 13, 2010

I have used ibator for mybatis 3.0.

Comment by zsum...@gmail.com, Oct 13, 2010

track out source from trunk and build with maven in my project pom.xml with this plugin <plugin>

<groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.0-SNAPSHOT</version> <executions>
<execution>
<id>Generate MyBatis? Artifacts</id> <goals>
<goal>generate</goal>
</goals>
</execution>
</executions> <configuration>
<configurationFile>generatorConfig.xml</configurationFile> <jdbcDriver>org.postgresql.Driver</jdbcDriver> <jdbcURL>jdbc:postgresql://10.10.10.10:5432/m</jdbcURL> <jdbcUserId></jdbcUserId> <jdbcPassword></jdbcPassword> <overwrite>true</overwrite>
</configuration> <dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-systests-common</artifactId> <version>1.3.0-SNAPSHOT</version>
</dependency> <dependency>
<groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <version>8.4-701.jdbc4</version>
</dependency>
</dependencies>
</plugin>

and my generatorConfig.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC

"-//mybatis.org//DTD MyBatis? Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>

<context id="DefualtJava5" targetRuntime="MyBatis3">
<property name="suppressTypeWarnings" value="true" />

<plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin" /> <plugin type="org.mybatis.generator.plugins.SerializablePlugin" /> <plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" /> <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">
<property name="searchString" value="Example$" /> <property name="replaceString" value="Criteria" />
</plugin> <plugin type="org.mybatis.generator.plugins.MapperConfigPlugin">
<property name="targetPackage" value="META-INF/mybatis" /> <property name="targetProject" value="MAVEN" />
</plugin>
<jdbcConnection driverClass="org.postgresql.Driver"
connectionURL="jdbc:postgresql://10.10.10.10:5432/m" userId="" password="" />
<javaModelGenerator targetPackage="server.beans"
targetProject="MAVEN"> <property name="enableSubPackages" value="false" /> <property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="server.mybatis.mapper"
targetProject="MAVEN"> <property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER"
targetPackage="mybatis.mapper" targetProject="MAVEN"> <property name="enableSubPackages" value="false" />
</javaClientGenerator>
<table schema="dict" tableName="v_station_cn" domainObjectName="Station"
alias="s" enableInsert="false" enableUpdateByPrimaryKey="false" enableDeleteByPrimaryKey="false" enableDeleteByExample="false" enableUpdateByExample="false" />
</context>

</generatorConfiguration>

Comment by nagro...@gmail.com, Oct 15, 2010

Dudes, honestly isn't there an easier way? I've never used Maven never mind the hassle of checking out source code from version control. Can you please post a link to a alpha/beta/rc somewhere?

Comment by project member eduardo.macarron, Oct 16, 2010
Comment by gfrancis1, Oct 20, 2010

yaay

Comment by nagro...@gmail.com, Oct 21, 2010

Thank you!!!

You guys were scaring me for a bit. The best persistence framework was looking vulnerable.

Thanks again, keep up the great work!

Comment by g.m.brus...@gmail.com, Oct 26, 2010

Reply to Comment by yuanhuiwu, Jul 27, 2010:

http://www.mail-archive.com/dev@ibatis.apache.org/msg01931.html

Comment by jacky...@gmail.com, May 8, 2011

How can I generate the bean with property name "userName" with the table column "USER_NAME"?

Comment by zhanglub...@gmail.com, May 9, 2011

hi, jacky...@gmail.com,You can set the useActualColumnNames value to false.like this:

<table schema="" tableName="RM_CUSTOM_QUERY" domainObjectName="CustomQuery">
<property name="useActualColumnNames" value="false" />
</table>
Comment by alaurage...@gmail.com, May 27, 2011

Can anyone tell me how to create DAO classes? I think it has something do do with <javaClientGenerator>, but I can't find anything on the Internet, the user group, or the documenation. I also tried using the old <daoGenerator> tag, but it's not part of the latest DTD.

Please help, where is it?!

Comment by yjc2...@gmail.com, Jul 17, 2011

When to support Eclipse 3.7

Comment by nogrief, Sep 16, 2011

support eclipse Indigo? when

Comment by project member jeffgbut...@gmail.com, Sep 16, 2011

The generator works on Eclipse 3.7/Indigo. Be adventurous - give it a try!

Comment by 229594...@163.com, Sep 29, 2011

Hello, for mybatis-Generator I have a problem, I hope you will return to the message, my project is in use spring3.05 + myabatis3.x + struts2, I saw the MGB with the help of documents that modify the method to add the completion of each operation time will return it to generate the id, but I use this code MBG myabtis generated by using the Add function always returns the id is 1

Comment by wahedk...@gmail.com, Dec 14, 2011

I can't install MyBatis? Generator on eclipse Indigo 3.7, I got: "...No repository found containing: osgi.bundle,oracle.database.driver.jdk14,10.2.0.1" error Looks belong to oracle driver or OEPE, is it required?

Comment by luc...@gmail.com, Apr 19, 2012

could anyone tell me how to use it as eclipse plugin, seems like cannot work on eclipse Indigo

Comment by jean-mar...@geotoolkit.net, Apr 19, 2012

MyBatis? Generator works well as eclipse plugin. It is important to set DB driver class path exemple : <classPathEntry location="D:\Workspace\External\OracleDriver11g\ojdbc6_g.jar"/> and to set javaModelGenerator targetPackage, sqlMapGenerator targetPackage and javaClientGenerator type="XMLMAPPER" targetPackage as source folder. Can you give more information on yours symptoms. Regards,


Sign in to add a comment
Powered by Google Project Hosting