我正在尝试利用MOxy的@XmlInverseReference注释对3个entites进行编组。我的场景非常反映这里提供的示例 provided here
实体A包含实体B的集合,实体B又拥有实体C的集合。不同之处在于实体B中的C集合使用自定义比较器进行排序。当我尝试编组树时,我得到一个ClassCastException,其中检查实体B中的集合是否包含实体A,导致自定义比较器中的异常只接受实体C
所以这里是A
中B集合的声明@XmlElement
private Set<AssignmentPeriod> periods = new LinkedHashSet<AssignmentPeriod>();
这是B中C的集合,使用自定义比较器
进行排序@XmlElement
@XmlInverseReference(mappedBy="assignmentPeriod")
@Sort(type = SortType.COMPARATOR,comparator=AssignmentPeriodRateComparator.class)
private Set<AssignmentPeriodRate> rates = new LinkedHashSet<AssignmentPeriodRate>();'
最后反过来引用C中的实体B
@XmlElement
@XmlInverseReference(mappedBy="rates")
private AssignmentPeriod assignmentPeriod;
当我删除对比较器的任何引用时,它的编组绝对正常,当我添加比较器注释时,我得到一个类转换异常,其中检查List of AssignmentPeriodRate以查看是否包含CandidateAssignment类型的对象
堆栈跟踪如下。任何指针都会感激不尽!
Caused by: java.lang.ClassCastException: uk.co.rullion.mypayroll.entities.assignment.CandidateAssignment cannot be cast to uk.co.rullion.mypayroll.entities.assignment.AssignmentPeriodRate
at uk.co.rullion.mypayroll.entities.assignment.AssignmentPeriodRateComparator.compare(AssignmentPeriodRateComparator.java:1) [myPayrollEntities-0.0.1-SNAPSHOT.jar:]
at java.util.TreeMap.getEntryUsingComparator(Unknown Source) [rt.jar:1.7.0_17]
at java.util.TreeMap.getEntry(Unknown Source) [rt.jar:1.7.0_17]
at java.util.TreeMap.containsKey(Unknown Source) [rt.jar:1.7.0_17]
at java.util.TreeSet.contains(Unknown Source) [rt.jar:1.7.0_17]
at org.hibernate.collection.internal.PersistentSet.contains(PersistentSet.java:171) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.eclipse.persistence.internal.queries.CollectionContainerPolicy.contains(CollectionContainerPolicy.java:113) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.queries.ContainerPolicy.contains(ContainerPolicy.java:701) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.queries.ContainerPolicy.contains(ContainerPolicy.java:1) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.XMLCompositeCollectionMappingNodeValue.marshal(XMLCompositeCollectionMappingNodeValue.java:97) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:149) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:102) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext.marshal(ObjectMarshalContext.java:59) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.XPathNode.marshal(XPathNode.java:401) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:240) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:118) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:1) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.XMLCompositeCollectionMappingNodeValue.marshalSingleValue(XMLCompositeCollectionMappingNodeValue.java:324) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.XMLCompositeCollectionMappingNodeValue.marshal(XMLCompositeCollectionMappingNodeValue.java:104) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:149) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:102) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext.marshal(ObjectMarshalContext.java:59) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.XPathNode.marshal(XPathNode.java:401) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:240) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:118) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:1) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:751) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshalStreamOrWriter(XMLMarshaller.java:1128) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:1079) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:1034) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:684) [eclipselink-2.5.1-RC1.jar:2.5.1.v20130824-981335c]
... 35 more
答案 0 :(得分:0)
注意:我是EclipseLink JAXB (MOXy)主管,是JAXB (JSR-222)专家组的成员。
此问题(请参阅:http://bugs.eclipse.org/416875)已在EclipseLink 2.5.1和2.6.0流中得到修复。您可以从以下链接下载2013年9月11日开始的每晚构建:
我已经确认了你所看到的问题。您可以使用以下错误来跟踪我们在此问题上的进展: