我有三个表: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;
....
}
我使用的(没有休眠)是:
由于
答案 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?