Why can't a JPA mapping attribute be a LinkedHashset?

Motivated by this question, I tried to change the following:

@ManyToMany(cascade={CascadeType.REMOVE, CascadeType.MERGE}) private Set<Expression> exps = new LinkedHashSet<Expression>(); 

in

  @ManyToMany(cascade={CascadeType.REMOVE, CascadeType.MERGE}) private LinkedHashSet<Expression> exps = new LinkedHashSet<Expression>(); 

However, such a movement leads to:

 Exception [EclipseLink-1] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.DescriptorException 

Exception Description: The [exps] attribute is not declared as type ValueHolderInterface, but its display uses indirect. Mapping: org.eclipse.persistence.mappings.ManyToManyMapping [exps] Descriptor: RelationalDescriptor (com.mysimpatico.memoplatform.persistence.entities.Meaning β†’ [DatabaseTable (MEANING)])

How do I assume in JPA2 to achieve the desired behavior?

+1
eclipselink
source share
2 answers

Only standard interface types are allowed as attribute types in JPA. Why are you changing the attribute type? With the original definition, the base collection is still your regular type.

+3
source share

I believe that EclipseLink will allow you to use a specific collection type if you set fetch to EAGER. When the link is LAZY, EclipseLink requires you to put your own lazy collection in place of the value. EclipseLink defines a lazy list, set, and map, but not a LinkedHashSet.

Please note that the JPA specification requires the use of the Collection, Set, List, or Map interface; impls are not allowed. If order is important, you should simply use the List.

Technically, it should be possible to support the implementation of the collection with LAZY collections, so please write down the bug / improvement for this.

+2
source share

All Articles