我有三张桌子: 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;
....
}我所使用的(没有hibernate)是:
谢谢
发布于 2016-05-19 14:21:52
正如我理解您的问题一样,您需要@ManyToOne或使用enum,如果只在开发阶段添加了新的workbook_type。
@Entity
class Country { //Country Dictionary
}
@Entity
class User {
@ManyToOne
private Country country;
}请参阅How to design tables for data dictionary when using hibernate?
https://stackoverflow.com/questions/37325409
复制相似问题