我正在尝试 @XmlIDREF
参考方法。注释是:
/**
* getter for Attribute/List<Attribute> attributes
* @return attributes
*/
@XmlElementWrapper(name="attributes")
@XmlElements({
@XmlElement(name="Attribute", type=AttributeJaxbDao.class)
})
@XmlIDREF
public List<Attribute> getAttributes() {
这导致错误消息:
javax.xml.bind.JAXBException:
Exception Description: Since the property or field [attributes] is set as XmlIDREF, the target type of each XmlElement declared within the XmlElements list must have an XmlID property. Please ensure the target type of XmlElement [Attribute] contains an XmlID property.
- with linked exception:
[Exception [EclipseLink-50035] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.JAXBException
Exception Description: Since the property or field [attributes] is set as XmlIDREF, the target type of each XmlElement declared within the XmlElements list must have an XmlID property. Please ensure the target type of XmlElement [Attribute] contains an XmlID property.]
at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:832)
at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:143)
虽然AttributeJaxbDao
有注释:
/**
* getter for xsd:string/String id
* @return id
*/
@XmlAttribute(name="id")
@XmlID
public String getId() {
@XmlIDREF
“标准使用” /有两个不同之处@XmlID
:
- AttributeJaxbDao 是派生类——注解在超类中
@XmlElement
属性是一个接口 - 类型已在注释中专门命名为 AttributeJaxbDao.class
在这种情况下如何出现错误?有没有办法解决这个问题。我想避免被迫不使用接口和泛化。