在JPA Hibernate中映射队列集合 [英] Mapping Queue collections in JPA Hibernate

查看:158
本文介绍了在JPA Hibernate中映射队列集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在JPA / hibernate中拥有以下集合映射?

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

private Deque< Child>儿童;

引发错误

 非法尝试将非集合映射为@OneToMany,@ManyToMany或@CollectionOfElements 

我正在使用JPA 2.0与Hibernate 3不同,JPA不支持Deque。在JPA 2.0规范中,解释如下:


集合值持久字段和属性必须以
的形式定义以下集合接口接口,而不考虑实体类是否遵守上述JavaBeans方法
惯例以及是否使用字段或属性访问的

java.util。 Collection,java.util.Set,java.util.List [3],java.util.Map。集合实现类型可以被
用于应用程序初始化字段或属性之前实体
被持久化。一旦实体变为托管(或分离),
后续访问必须通过接口类型。


我建议添加到提供所需Deque功能的实体方法(或将视图展示为Deque到持久列表)。其他可能性是定制收集(Thor84no)。


Is it possible to have following collection mapping in JPA / hibernate

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

private Deque<Child> childrens;

It throws error

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

I am using JPA 2.0 with Hibernate 3

解决方案

No, JPA does not support Deque. In JPA 2.0 specification this is explained following way:

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.

I would suggest to add to entity methods that provide needed Deque functionality (or expose view as Deque to persisted list). Other possibility is custom collection as suggested in comments (Thor84no).

这篇关于在JPA Hibernate中映射队列集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆