使用hibernate工具进行惰性映射? [英] Lazy mapping with hibernate tools?

查看:119
本文介绍了使用hibernate工具进行惰性映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中有两个表 A B 。我的表 B 我用一个Integer idA 来引用表 A code>。 (idA是B的外键)
当我使用hibernate-tools进行反向工程时,我生成了两个Java对象。

I have two tables A and B in my database. I the table B I have a reference to the table A by an Integer idA. (idA is a foreign key for B) When I do reverse engineering using hibernate-tools, I generate two Java objects.

public class A{
  int id;
} 

public class B{
  int id;
  A a;
} 

但我想拥有

But I want to have

public class B{
  int id;
  int idA;
}  

我该怎么做?

Thanks,

推荐答案

所以我找到了一个解决方案:创建一个自定义 ReverseEngineeringStrategy 并将 excludeForeignKeyAsManytoOne 方法的返回更改为 true

So I found a solution: create a custom ReverseEngineeringStrategy and change the return of excludeForeignKeyAsManytoOne method to true.

public class MyReverseEngineeringStrategy extends DelegatingReverseEngineeringStrategy {

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

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

}

这篇关于使用hibernate工具进行惰性映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆