我正在将 Hibernate OGM 与 MongoDB 一起使用,并且有一个如下所示的实体:
@Entity
public class Card implements Serializable, Comparable<Card>
{
private static Logger logger = LoggerFactory.getLogger(Card.class);
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String id;
...
@OneToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private Card cardRef;
@OneToOne(mappedBy = "cardRef")
private Card cardParent;
// pinning : represents the owner's card
@ManyToOne
private Card cardPinOrigin;
// List of the cards that have pinned the current
@OneToMany(mappedBy = "cardPinOrigin")
private List<Card> cardsPinned = new ArrayList<>();
...
}
当我通过使用“cardsPinned”列表中的卡片更新卡片来存储卡片时,它存储在数据库中:
“家长”卡
{
"_id" : "39d83887-e466-45c5-a5e8-1dfd5c22ed8a",
"cardPinOrigin" : [
{
"id" : "478f6f83-161f-44dc-86c4-844f73084ffb"
}
],
....
}
和“儿童”卡
{
"_id" : "478f6f83-161f-44dc-86c4-844f73084ffb",
"cardPinOrigin_id" : "39d83887-e466-45c5-a5e8-1dfd5c22ed8a",
...
}
我的问题是当我从数据库中获取数据时,固定卡片列表(cardsPinned java List)总是空的。有人知道为什么吗?
提前感谢您的回答。