mariadbmybatismybatis-generator

Mybatis Generator missing methods


I found that there were some missing methods in generated mapping interface while connecting mariadb , what mapper generated like is:

public interface Mapper {
    int insert(Record record);

    int insertSelective(Record record);
}

what should be:

public interface Mapper {
    int deleteByPrimaryKey(Record id);

    int insert(Record record);

    int insertSelective(Record record);

    City selectByPrimaryKey(Record id);

    int updateByPrimaryKeySelective(Record record);

    int updateByPrimaryKey(Record record);
}

I've tried several different connector lib, both mysql-connector-java and mariadb-java-client. And code generated is correct while connecting mysql, that reminds me if mybatis generator 1.3.6 doesn't support mariadb 5.7.20? BTW the verison of mysql was 5.7. here is my config.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>

  <classPathEntry location="/maven/repo/org/mariadb/jdbc/mariadb-java-client/2.2.1/mariadb-java-client-2.2.1.jar" />

  <context id="mybatisgen" targetRuntime="MyBatis3">

    <commentGenerator>
      <property name="suppressAllComments" value="true" />
      <property name="suppressDate" value="true" />
    </commentGenerator>

    <jdbcConnection driverClass="org.mariadb.jdbc.Driver"
        connectionURL="jdbc:mariadb://127.0.0.1:3306/db?characterEncoding=utf8"
        userId="user"
        password="password">
    </jdbcConnection>

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

    <javaModelGenerator targetPackage="me.model" targetProject="src">
      <property name="enableSubPackages" value="true" />
      <property name="trimStrings" value="true" />
    </javaModelGenerator>

    <sqlMapGenerator targetPackage="me.mapper"  targetProject="src">
      <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>

    <javaClientGenerator type="XMLMAPPER" targetPackage="me.dao"  targetProject="src">
      <property name="enableSubPackages" value="true" />
    </javaClientGenerator>

    <table tableName="test_table" domainObjectName="ATable" 
        enableCountByExample="false" enableUpdateByExample="false"
        enableDeleteByExample="false" enableSelectByExample="false"
        selectByExampleQueryId="false">     
    </table>

  </context>
</generatorConfiguration>

Solution

  • This happens when MyBatis Generator cannot obtain the primary key information from the JDBC driver (it calls DatabaseMetaData.getPrimaryKeys).

    You can use the VirtualPrimaryKey plugin (documented at http://www.mybatis.org/generator/reference/plugins.html) to manually specify the primary key for a table when the JDBC driver is unable to return that information.