0
我試圖映射實體,所以我將有以下或類似的效果(最好不OrderItem.quantity):的Hibernate映射列表
這裏是我的實體:
public class Orders implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne
private UserCreds user;
@OneToMany
private List<Item> orderedItems;
我結束了與OrdersItem連接表映射只有2列: item_id和order_id,都是鍵 因此它不會讓我堅持重複項目的順序。添加ID列的OrderItems應該做的伎倆:
OrdersItem table that I except:
| ID | ORDER_ID | ITEM_ID
1 25 31
2 25 31
3 25 12
4 25 12
5 25 62
等。 但我就是不可能得到那個工作,也許我的解決方案是完全錯誤的?
「JPA 2.0規範明確指出@ ElementCollection適用於基本類型和可嵌入類型」,我認爲我需要兩個類作爲@ Entity。下面的解決方案導致 org.hibernate.AnnotationException:使用@ OneToMany或@ ManyToMany以未映射的類爲目標:Entity.Orders.itemQuantities [java.lang.Integer] (targetClass)將不會幫助 – stzmk
不完全請參閱編輯 – kostja