Hibernate 工具:如何忽略外键?

Hibernate tools: how to ignore foreign keys?

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

class User {
 private City city;
...
}

我要

class User{
private Integer cityId;
...
}

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


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;
    }

}