The <sqlMapGenerator> Element

The <sqlMapGenerator> element is used to define properties of the SQL map generator. The SQL Map Generator builds a MyBatis/iBATIS formatted SQL map XML file for each introspected table.

If iBATIS2 is targeted, then this element is a required child element of the <context> element.

If MyBatis3 is targeted, then this element is a required child element of the <context> element only if your chosen javaClientGenerator requires XML.

If you do not specify a javaClientGenerator, then the following rules apply:

  • If you specify an sqlMapGenerator, then MBG will generate SQL map XML files and model classess only.
  • If you do not specify an sqlMapGenerator, then MBG will generate model classes only.

Required Attributes

Attribute Description
targetPackage This is the package where the generated SQL Maps will be placed. In the default generators, the property "enableSubPackages" controls how the actual package is calculated. If true, then the calculated package will be the targetPackage plus sub packages for the table's catalog and schema if they exist. If false (the default) then the calculated package will be exactly what is specified in the targetPackage attribute. MyBatis Generator (MBG) will create folders as required for the generated packages.
targetProject This is used to specify a target project for the generated SQL maps. When running in the Eclipse environment, this specifies the project and source folder where the objects will be saved. In other environments, this value should be an existing directory on the local file system. MBG will not create this directory if it does not exist.

Optional Attributes

None

Child Elements

Supported Properties

This table lists the properties of the default SQL Map generators that can be specified with the <property> child element:

Property Name Property Values
enableSubPackages This property is used to select whether MBG will generate different Java packages for the objects based on the catalog and schema of the introspected table.

For example, suppose a table MYTABLE in schema MYSCHMA. Also suppose that the targetPackage attribute is set to "com.mycompany". If this property is true, the generated SQL Map for the table will be placed in the package "com.mycompany.myschema". If the property is false, the generated SQL Map will be placed in the "com.mycompany" schema.

The default value is false.

Example

This element specifies that we always want to place generated SQL Maps in the "'test.model" package and that we want to use subpackages based on the table schema and catalog.

<sqlMapGenerator targetPackage="test.model"
     targetProject="\MyProject\src">
  <property name="enableSubPackages" value="true" />
</sqlMapGenerator>