MyBatis Generator failed to get comments when generating the corresponding entity class of Oracle Database

Keywords: Programming Mybatis Oracle JDBC Database

Recently, a problem was found when using mybatis generator to generate the entity classes corresponding to Oracle database. It is hereby recorded.
Because the project uses swagger2, we want to generate the corresponding @ ApiMode and @ ApiModelProperty annotations through table annotations and field annotations when generating entity classes. However, it is found that there is no effect. After checking the source code, it is found that the OracleDatabaseMetaData class will determine whether the value of the remarksReporting property is true. When it is true, the comment will be obtained. Therefore, only one more attribute is added to the JDBC connection configuration <property name="remarksReporting" value="true"/> Just.

The source code is as follows:

package org.mybatis.generator.api;

public class MyBatisGenerator {
    public void generate(ProgressCallback callback, Set<String> contextIds,
            Set<String> fullyQualifiedTableNames, boolean writeFiles) throws SQLException,
            IOException, InterruptedException {
        // Only focus on the key code, the previous code is not copied in
        for (Context context : contextsToRun) {
            // What's important is the method
            context.introspectTables(callback, warnings,
                    fullyQualifiedTableNames);
        }
        // The following method logic is ignored
    }
}
package org.mybatis.generator.config;

public class Context extends PropertyHolder {
    public void introspectTables(ProgressCallback callback,
            List<String> warnings, Set<String> fullyQualifiedTableNames)
            throws SQLException, InterruptedException {
        // The previous method logic ignores the importance of the databaseIntrospector.introspectTables method
        List<IntrospectedTable> tables = databaseIntrospector.
            .introspectTables(tc);
        if (tables != null) {
            introspectedTables.addAll(tables);
        }
    }
}
package org.mybatis.generator.internal.db;

public class DatabaseIntrospector {
    public List<IntrospectedTable> introspectTables(TableConfiguration tc) {
        // The previous method logic ignores the importance of the calculateintrospecttables method
        List<IntrospectedTable> introspectedTables = calculateIntrospectedTables(
                tc, columns);
    }

   private List<IntrospectedTable> calculateIntrospectedTables(
            TableConfiguration tc,
            Map<ActualTableName, List<IntrospectedColumn>> columns) {
        // The previous method logic ignores the importance of the enhanced introduced table method
        enhanceIntrospectedTable(introspectedTable);
   }

    private void enhanceIntrospectedTable(IntrospectedTable introspectedTable) {
        // The previous method logic ignored the important one is the databaseMetaData.getTables method
        ResultSet rs = databaseMetaData.getTables(fqt.getIntrospectedCatalog(), fqt.getIntrospectedSchema(),
     }
}
package oracle.jdbc;

public class OracleDatabaseMetaData implements AdditionalDatabaseMetaData {
	// No source code for oralce is found here
    public synchronized ResultSet getTables(String var1, String var2, String var3, String[] var4) throws SQLException {
        String var6 = "       c.comments AS remarks\n";
        String var7 = "       NULL AS remarks\n";
        // It can be seen here that we will judge whether the value of remarksReporting is true. If it is true, we can check the original comment. Otherwise, we will treat null value as a comment
        if (this.connection.getRemarksReporting()) {
            var22 = var22 + var6 + var8;
        } else {
            var22 = var22 + var7 + var9;
        }
    }
}

Posted by Shendemiar on Thu, 19 Dec 2019 10:02:11 -0800