[英]Mapping multiple Java objects to different rows in same table with Hibernate
[英]Hibernate mapping for different items in the same table
我有以下三個類[Promotion, Product and Image]
。 Promotion
有一個Image
。 Product
具有Image's
列表/集合。 將來可能會有新的類也有Image
或Image's
Collection of Image's
。
我想將所有圖像放在同一個圖像表中(eg:: image_table)
。 這意味着Promotion
的圖像和Product
中的圖像集合都將進入同一張表。
例如,我不能在Image
類中放置兩個@OneToMany/@ManyToOne
注釋,因為這樣在 Image table (eg:: image_table)
會有兩個不同的外鍵(Promotion_FK and Product_FK)
(eg:: image_table)
。 將來如果有更多具有圖像的類,那么我必須添加額外的@OneToMany/@ManyToOne
注釋。
有沒有辦法在 Hibernate 中映射此功能?
如果我的設計不好,在現實世界中他們如何將屬於不同類的圖像存儲在同一張表中?
然后嘗試使用單向映射
例如,促銷有形象,產品有形象,但反之亦然
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.