以下は、私のクラスと OXM のマッピングです。phoneType を phone の子要素にしたい場合、以下の例外が発生する理由がわかりません
public class PhoneNumber
{
public enum PhoneType
{
Cell, Home
};
private PhoneType phoneType;
private String type;
private String number;
public String getType()
{
return type;
}
public void setType(final String type)
{
this.type = type;
}
public String getNumber()
{
return number;
}
public void setNumber(final String number)
{
this.number = number;
}
public void setPhoneType(final PhoneType phoneType)
{
this.phoneType = phoneType;
}
public PhoneType getPhoneType()
{
return phoneType;
}
}
OXM
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/oxm http://www.eclipse.org/eclipselink/xsds/eclipselink_oxm_2_4.xsd"
version="2.4" package-name="blog.bindingfile" xml-mapping-metadata-complete="true">
<xml-schema namespace="http://www.example.com/customer" element-form-default="QUALIFIED" />
<java-types>
<java-type name="Customer">
<xml-root-element name="customer"/>
<xml-type prop-order="lastName firstName address phoneNumbers" />
<java-attributes>
<xml-element java-attribute="firstName" name="first-name" />
<xml-element java-attribute="lastName" name="last-name" />
<xml-element java-attribute="phoneNumbers" name="phone-number" />
</java-attributes>
</java-type>
<java-type name="BaseCustomer" xml-transient="true">
<xml-root-element/>
</java-type>
<java-type name="PhoneNumber">
<java-attributes>
<xml-attribute java-attribute="type" />
<xml-value java-attribute="number" />
<xml-element java-attribute="phoneType" name="phone-type"/>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
例外
Caused by: Exception [EclipseLink-50010] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.JAXBException
Exception Description: The property or field phoneType must be an attribute because another field or property is annotated with XmlValue.
at org.eclipse.persistence.exceptions.JAXBException.propertyOrFieldShouldBeAnAttribute(JAXBException.java:246)
at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.finalizeProperties(AnnotationsProcessor.java:1011)
at org.eclipse.persistence.jaxb.compiler.XMLProcessor.processXML(XMLProcessor.java:412)
at org.eclipse.persistence.jaxb.compiler.Generator.<init>(Generator.java:102)
at org.eclipse.persistence.jaxb.JAXBContext$ContextPathInput.createContextState(JAXBContext.java:768)
... 11 more