Frames No Frames

The <javaModelGenerator> Element

The <javaModelGenerator> element is used to define properties of the Java model generator. The Java Model Generator builds primary key classes, record classes, and Query by Example classes that match the introspected table. This element is a required child element of the <abatorContext> element.

If you don't specify a user defined type, Abator will select a default generator based on the value of the generatorSet property of the <abatorContext> element. See the notes on that page for features of the different types of generators.

Required Attributes

Attribute Description
targetPackage This is the package where the generated classes will be placed. In the default generator, 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. Abator will create folders as required for the generated packages.
targetProject This is used to specify a target project for the generated objects. 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. Abator will not create this directory if it does not exist.

Optional Attributes

Attribute Description
type This can be used to specify a user provided Java model generator. The class must implement the interface org.apache.ibatis.abator.api.JavaModelGenerator, and must have a public default constructor. The attribute also accepts the special value DEFAULT in which case the default implementation will be used (this has the same effect as not specifying the type).

Child Elements

Supported Properties

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

Property Name Property Values
enableSubPackages This property is used to select whether Abator 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 objects for the table will be placed in the package "com.mycompany.myschema". If the property is false, the generated objects will be placed in the "com.mycompany" schema.

The default value is false.

rootClass This property can be used to specify a root class for all generated Java model objects. Abator will specify this value as the super class of the primary key object, if the table has a primary key, or the record object otherwise. This value may be overridden by specifying the rootClass property on a Table configuration.

Important: If Abator is able to load the root class, Abator will not override a property in the root class that exactly matches a property that Abator would normally generate. An exact match of a property is defined as follows

  • Property name matches exactly
  • Property is of the same type
  • Property has a "getter" method
  • Property has a "setter" method

You may use the "rootClasspath" property to add entries to the rootClass lookup classpath if necessary.

If specified, the value of this property should be a fully qualified class name (like com.mycompany.MyRootClass).

rootClasspath This property can be used to specify a class path for the "rootClass" specified here or on the <table> element. Abator will check in the rootClass and will not generate a property if the property exists in the rootClass. If not specified, Abator will attempt to load the rootClass through the current thread context classloader. If Abator cannot find and load the rootClass, then Abator will generate all properties.

This property is a semi-colon (;) delimited string of classpath entries.

trimStrings This property is used to select whether Abator adds code to trim the white space from character fields returned from the database. This can be useful if your database stores data in CHAR fields rather than VARCHAR fields. When true, Abator will insert code to trim character fields.

The default value is false.


This element specifies that we always want to place generated classes in the "'test.model" package and that we want to use subpackages based on the table schema and catalog. We also want String columns trimmed.

<javaModelGenerator targetPackage="test.model"
  <property name="enableSubPackages" value="true" />
  <property name="trimStrings" value="true" />