簡體   English   中英

同一個表中不同項目的休眠映射

[英]Hibernate mapping for different items in the same table

我有以下三個類[Promotion, Product and Image] Promotion有一個Image Product具有Image's列表/集合。 將來可能會有新的類也有ImageImage'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注釋。

  1. 有沒有辦法在 Hibernate 中映射此功能?

  2. 如果我的設計不好,在現實世界中他們如何將屬於不同類的圖像存儲在同一張表中?

然后嘗試使用單向映射

例如,促銷形象產品形象反之亦然

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM