Hibernate工具:如何忽略外键?

时间:2015-02-21 08:10:37

标签: java hibernate hibernate-tools

Hibernate工具(用于Eclipse)逆向工程生成带参考字段的POJO。如何忽略数据库关系?例如,

class User {
 private City city;
...
}

我想要

class User{
private Integer cityId;
...
}

1 个答案:

答案 0 :(得分:1)

最后,我找到了我的问题的答案。我创建了逆向工程策略类并覆盖了一些方法:


public class RevengStrategy extends DelegatingReverseEngineeringStrategy  {

    public RevengStrategy(ReverseEngineeringStrategy delegate) {
        super(delegate);
    }

    @Override
    public boolean excludeForeignKeyAsManytoOne(String keyname, TableIdentifier fromTable, List fromColumns, TableIdentifier referencedTable, List referencedColumns) {
        return true;
    }

    @Override
    public boolean excludeForeignKeyAsCollection(String keyname, TableIdentifier fromTable, List fromColumns, TableIdentifier referencedTable, List referencedColumns) {
        return true;
    }

}