我有如下数据库方案:
在我的Commande
java类中我有这个(省略了这个问题的无用数据):
@Entity
@Table(name = "commande")
public class Commande {
private int id;
private Timestamp date;
private Person client;
private Magasin shop;
private HashMap<Article,Integer> detail;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
...
public HashMap<Article,Integer> getDetail() {
return detail;
}
public void setDetail(HashMap<Article,Integer> detail) {
this.detail = detail;
}
...
我希望当我读取数据时,我可以在 HashMap 中获取所有“detail_commande”数据
detail_commande commande
|id_commande|id_article|qqte_cmde| |id| date |id_person|id_shop|
|===========|==========|=========| |==|========|=========|=======|
| 0 | 0 | 15 | | 0|1-2-2019| 0 | 2 |
| 0 | 2 | 5 |
| 0 | 4 | 1 |
如果我想读取命令号0的数据,它必须是:
id : 0
date : 1-2-2019
person : personData
shop : shopData
datail : [articleData0 -> 15,
articleData2 -> 5,
articleData4 -> 1 ]
但我不明白注释可以做到这一点。
最佳答案
您需要在细节 HashMap 上使用 @ManyToMany 注释,它将成为文章列表。阅读本文了解:https://www.baeldung.com/hibernate-many-to-many
关于java - 使用注释从 hibernate 中的其他表映射数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54387532/