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

标签 java hibernate jpa-2.0

是否可以在 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/

相关文章:

java - JPA 中存在不同的问题

java - 如何从 Java 中的 .dat 文件中读取一行然后需要将其分开?

java - Apache tomcat 与 Eclipse 动态 Web 模块 3.0 的问题

java - JPA 子查询将列表返回到构造函数中

java - JPA 合并第一次不起作用,但第二次起作用

hibernate - 在 Hibernate 中使用 CascadeType

java - NetBeans w/Gradle 支持测试系统环境

java - 来自外部软件的 Thunderbird 脚本

transactions - 在 Java EE 中调试事务

java - JPA 在 Spring 中到底是如何工作的?一些疑问