查阅列的Hibernate注释

时间:2016-05-19 13:54:25

标签: java hibernate

我有三个表:po_dtl和workbook_types。 每个采购订单行(po_dtl)都有“workbook_code”列来引用workbook_types。 基本上,po_dtl.workbook_code只是workbook_types.workbook_code的查找代码。

简化的java类是

@Entity
@Table(name="po_dtl")
public class PurchaseOrderDtl {
    @Id
    @Column(name = "po_dtl_id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "po_dtl_s")
    @SequenceGenerator(name = "po_dtl_s", sequenceName = "po_dtl_s", allocationSize = 1, initialValue = 1)
    private long id;

    @Column(name = "price_base", length = 7)
    private int priceBase;

    // ??? What is the annotation for workbook_Types?
    private WorkbookType workbookType;

    ....
}

而workbook_types

@Entity
@Table(name = "workbook_types")
public class WorkbookType {

    @Id
    @Column(name = "workbook_code")
    private String workbookCode;

    @Column(name = "description", length = 255)
    private String description;

    @Column(name = "file_root_path", length = 255)
    private String fileRootPath;
    ....
}

我使用的(没有休眠)是:

  • workbook_types.workbook_code包含字符串“wbook_finance”, “wbook_marketing”
  • 每个po_dtl.workbook_code都包含“wbook_finance”或 “wbook_marketing”
  • workbook_types将只包含2行且具有唯一的workbook_code,而po_dtl将包含许多行,但每行必须仅包含“wbook_finance”或“wbook_marketing”

由于

1 个答案:

答案 0 :(得分:0)

据我了解你的问题,你需要@ManyToOne 如果仅在开发阶段添加新的workbook_type,则使用枚举。

@Entity
class Country  { //Country Dictionary

}

@Entity
class User {
    @ManyToOne
    private Country country;
}

请参阅How to design tables for data dictionary when using hibernate?