gpt4 book ai didi

java - 在 JPA Hibernate 中映射队列集合

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:52:32 24 4
gpt4 key购买 nike

是否可以在 JPA/hibernate 中进行以下集合映射

@OneToMany(cascade={CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE},
fetch=FetchType.LAZY,mappedBy="parent")

private Deque<Child> childrens;

它抛出错误

Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements

我正在使用 JPA 2.0 和 Hibernate 3

最佳答案

不,JPA 不支持双端队列。在 JPA 2.0 规范中,这是按以下方式解释的:

Collection-valued persistent fields and properties must be defined in terms of one of the following collection-valued interfaces regardless of whether the entity class otherwise adheres to the JavaBeans method conventions noted above and whether field or property access is used: java.util.Collection, java.util.Set, java.util.List[3], java.util.Map. The collection implementa- tion type may be used by the application to initialize fields or properties before the entity is made persistent. Once the entity becomes managed (or detached), subsequent access must be through the interface type.

我建议添加到提供所需 Deque 功能的实体方法(或将 View 作为 Deque 公开到持久列表)。其他可能性是评论中建议的自定义集合 (Thor84no)。

关于java - 在 JPA Hibernate 中映射队列集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10104946/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com