1

In our team we started using MyBatis Generator version 1.3.1, and we just recently migrated to version 1.3.2 and found a change in the order of attributes of the generated POJOs.

Previously, the order of the attributes in the generated classes was alphabetical, but after the change, we've realized that in the XxxKey classes, i.e., the classes that match the primary key of the table, the order of the attributes is no longer alphabetical.

Example:

Version 1.3.1:

public class PoolChargingKey {
    private String billingCycle;
    private Integer commercialGroupId;
    private Short destinationId;
    private Integer tariffPlanId;
    private String trafficCase;
    private Integer zoneId;
[...]

Version 1.3.2:

public class PoolChargingKey {
    private Integer commercialGroupId;
    private Integer tariffPlanId;
    private Integer zoneId;
    private Short destinationId;
    private String basicService;
    private String trafficCase;
[...]

We are accessing the generated POJOs with reflection for some mocking utils, and the change in the attributes order broke it. We can fix the affected changes, but it would be great to indicate how the classes are generated.

Is it possible to do that? I guess the answer is no, but just in case. By the way, the attribute order in version 1.3.1 was alphabetic. In which order are the attributes generated in version 1.3.2?

Regards, Tomas.

4

2 回答 2

1

我在文档中没有看到有关属性顺序配置的任何内容。

但是,一种方法可以根据需要更改源代码。从org.mybatis.generator.codegen.mybatis3.model.IntrospectedTable.java,我看到添加到列表中的列的顺序是;

    List<IntrospectedColumn> answer = new ArrayList<IntrospectedColumn>();
    answer.addAll(primaryKeyColumns);
    answer.addAll(baseColumns);
    answer.addAll(blobColumns);

在 getAllColumns() 方法中。这些添加的列是List<IntrospectedColumn>. 我想也许如果你根据课堂上的这些列表对这些列表进行排序String actualColumnNameIntrospectedColumn也许你可以得到你想要的订单。

于 2014-01-08T07:13:44.403 回答
0

我也在 mybatis.user google groups 中问过这个问题,Jeff Butler 友好地回答了这个问题:

我们确实在这里进行了更改。这与以下问题有关:

https://code.google.com/p/mybatis/issues/detail?id=438

现在这些字段按“键顺序”保存。这意味着它们按照 JDBC 的 DatabaseMetaData.getPrimaryKeys() 函数返回的“KEY_SEQ”字段指定的顺序排列。

杰夫巴特勒

于 2014-01-09T09:12:15.227 回答