The <connectionFactory> Element

The <connectionFactory> element is used to specify a connection factory for obtaining the database connection required to introspect tables. MyBatis Generator uses JDBC's DatabaseMetaData class to discover the properties of the tables you specify in the configuration. One <connectionFactory> or <jdbcConnection> element is required for each <context> element.

Required Attributes

None

Optional Attributes

Attribute Description
type This may be used to specify the type of the user provided connection factory. The class must implement the interface org.mybatis.generator.api.ConnectionFactory 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

  • <property> (0..N) Note: for the default connection factory, any properties specified beyond what is detailed below will be added to the properties of the JDBC driver.

Supported Properties

This table lists the properties of the default connection factory that can be specified with the <property> child element:

Property Name Property Values
driverClass This property is used to specify the fully qualified class name of the JDBC driver. This property is required for the default connection factory.
connectionURL This property is used to specify the JDBC connection URL for the database. This property is required for the default connection factory.
userId This property is used to specify the User ID for the connection.
password This property is used to specify the password for the connection.

Example

This element will connect to an HSQLDB in memory database configured as aname:

<connectionFactory>
  <property name="driverClass" value="org.hsqldb.jdbcDriver"/>
  <property name="connectionURL" value="jdbc:hsqldb:mem:aname"/>
  <property name="userId" value="sa"/>
</connectionFactory>