The <javaTypeResolver> Element

The <javaTypeResolver> element is used to define properties of the Java Type Resolver. The Java Type Resolver is used to calculate Java types from database column information. The default Java Type Resolver attempts to make JDBC DECIMAL and NUMERIC types easier to use by substituting Integral types if possible (Long, Integer, Short, etc.) If this behavior is undesirable, set the property "forceBigDecimals" to "true". You can also substitute your own implementation if you want different behavior than the default. This element is an optional child element of the <context> element.

Required Attributes

None

Optional Attributes

Attribute Description
type This can be used to specify a user provided Java Type Resolver. The class must implement the interface org.mybatis.generator.api.JavaTypeResolver, 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 type resolver that can be specified with the <property> child element:

Property Name Property Values
forceBigDecimals This property is used to specify whether MyBatis Generator should force the use of java.math.BigDecimal for DECIMAL and NUMERIC fields, rather than substituting integral types when possible. The property supports these values:
false This is the default value
When the property is false or unspecified, the default Java type resolver will attempt to make JDBC DECIMAL and NUMERIC types easier to work with by substituting Integral types if possible. The substitution rules are as follows:
  • If the scale is greater then zero, or the length is greater than 18, then the java.math.BigDecimal type will be used
  • If the scale is zero, and the length is 10 through 18, then the Java type resolver will substitute a java.lang.Long.
  • If the scale is zero, and the length is 5 through 9, then the Java type resolver will substitute a java.lang.Integer.
  • If the scale is zero, and the length is less than 5, then the Java type resolver will substitute a java.lang.Short.
true When the property is true, the Java type resolver will always use java.math.BigDecimal if the database column is of type DECIMAL or NUMERIC.

Example

This element specifies that we always want to use the java.math.BigDecimal type for DECIMAL and NUMERIC columns:

<javaTypeResolver>
  <property name="forceBigDecimals" value="false" />
</javaTypeResolver>