[英]Changing from Collection to SortedSet
I'm changing a Collection to a SortedSet because I need it to always be in the same consistent order that they were created in. I've changed my model property from我正在将 Collection 更改为 SortedSet,因为我需要它始终保持与创建它们时相同的一致顺序。我已将我的 model 属性从
@OneToMany(cascade = CascadeType.ALL, mappedBy = "contentId")
private Collection<Footnote> footnoteCollection;
to到
@OneToMany(cascade = CascadeType.ALL, mappedBy = "contentId")
private SortedSet<Footnote> footnoteSortedSet;
and all relevant functions so Netbeans no longer shows any errors.以及所有相关功能,因此 Netbeans 不再显示任何错误。 When I run the app I get the error:
Exception Description: Could not load the field named [footnoteSortedSet] on the class [class com.mysite.cmt.model.Content_]. Ensure there is a corresponding field with that name defined on the class.
当我运行该应用程序时出现错误:
Exception Description: Could not load the field named [footnoteSortedSet] on the class [class com.mysite.cmt.model.Content_]. Ensure there is a corresponding field with that name defined on the class.
Exception Description: Could not load the field named [footnoteSortedSet] on the class [class com.mysite.cmt.model.Content_]. Ensure there is a corresponding field with that name defined on the class.
Since I've just changed this properly and relaunched my app I'm struggling to figure out why it's saying it's not set...因为我刚刚正确地改变了它并重新启动了我的应用程序,所以我正在努力弄清楚为什么它说它没有设置......
The error you are getting seems to be coming from the JPA metamodel.您收到的错误似乎来自 JPA 元模型。 I assume you are generating this in some way, if you don't use the metamodel in Criteria, then you don't need this and the error will go away.
我假设您正在以某种方式生成它,如果您不在 Criteria 中使用元模型,那么您不需要它并且错误将 go 消失。
The issue is that JPA only allows the collection interfaces, Map, List, Set, Collection.问题是JPA只允许集合接口,Map,List,Set,Collection。 So, while you could use a SortedSet in your new instances, object read from the database will use a special lazy List implementation.
因此,虽然您可以在新实例中使用 SortedSet,但从数据库读取的 object 将使用特殊的惰性 List 实现。
In EclipseLink, you can use a SortedSet if you mark the mapping as EAGER.在 EclipseLink 中,如果将映射标记为 EAGER,则可以使用 SortedSet。 I think the metamodel error was fixed, try the latest release.
我认为元模型错误已修复,请尝试最新版本。
SortedSet
javadoc to the rescue: SortedSet
javadoc 来拯救:
All elements inserted into a sorted set must implement the Comparable interface (or be accepted by the specified comparator).
插入有序集合的所有元素都必须实现 Comparable 接口(或被指定的比较器接受)。
Almost certainly, Footnote
does not implement Comparable
几乎可以肯定,
Footnote
没有实现Comparable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.