Why cannot a JPA mapping attribute be a LinkedHashset?

后端 未结 2 700
[愿得一人]
[愿得一人] 2021-01-24 09:27

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

 @ManyToMany(cascade={CascadeType.REMOVE, CascadeType.MERGE})
private Set exps         


        
相关标签:
2条回答
  • 2021-01-24 10:02

    I believe EclipseLink will allow you to use a concrete collection type if you set fetch to EAGER. When the relationship is LAZY EclipseLink requires to put its own lazy collection in place of the value. EclipseLink defines a lazy List, Set and Map, but no LinkedHashSet.

    Note the JPA spec requires the usage of the Collection, Set, List or Map interface, no impls are allowed. If order is important, you should just use a List.

    Technically it should be possible to maintain the collection implementation with LAZY collections, so please log a bug/enhancement for this.

    0 讨论(0)
  • 2021-01-24 10:20

    Only the standard interfaces types are allowed as attribute types in JPA. Why are you changing the type of the attribute? With the original definition the underlying collection is still your custom type.

    0 讨论(0)
提交回复
热议问题