从Collection更改为SortedSet [英] Changing from Collection to SortedSet

查看:72
本文介绍了从Collection更改为SortedSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Collection更改为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

@OneToMany(cascade = CascadeType.ALL, mappedBy = "contentId")
private Collection<Footnote> footnoteCollection;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "contentId")
private SortedSet<Footnote> footnoteSortedSet;

和所有相关功能,因此Netbeans不再显示任何错误.当我运行该应用程序时,出现错误: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.

and all relevant functions so Netbeans no longer shows any errors. 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.

由于我刚刚进行了适当的更改并重新启动了我的应用程序,所以我一直在努力弄清为什么它说未设置...

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

推荐答案

您收到的错误似乎来自JPA元模型.我假设您正在以某种方式生成此代码,如果您不使用Criteria中的元模型,那么您将不需要此代码,并且错误将消失.

The error you are getting seems to be coming from the JPA metamodel. 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.

问题是JPA仅允许收集接口Map,List,Set,Collection.因此,尽管您可以在新实例中使用SortedSet,但从数据库读取的对象将使用特殊的惰性List实现.

The issue is that JPA only allows the collection interfaces, 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.

在EclipseLink中,如果将映射标记为EAGER,则可以使用SortedSet. 我认为元模型错误已修复,请尝试使用最新版本.

In EclipseLink, you can use a SortedSet if you mark the mapping as EAGER. I think the metamodel error was fixed, try the latest release.

这篇关于从Collection更改为SortedSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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