Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping Queue collections in JPA Hibernate

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

like image 374
Dhananjay Avatar asked Feb 21 '23 20:02

Dhananjay


1 Answers

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).

like image 137
Mikko Maunu Avatar answered Mar 06 '23 00:03

Mikko Maunu