Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8399673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:22:04+00:00 2026-06-09T21:22:04+00:00

Below is my class and OXM mapping. Not sure why I am getting the

  • 0

Below is my class and OXM mapping. Not sure why I am getting the below exception if I want the phoneType to be a child element under 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>

Exception

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:22:06+00:00Added an answer on June 9, 2026 at 9:22 pm

    UPDATE

    To fully understand why you are seeing the exception we will look at a formatted fragment of XML. The question comes down to which text fragment the @XmlValue mapping corresponds to (the first, second, neither?)

    <phone-number type="TYPE">
        <phone-type>Cell</phone-type>
    </phone-number>
    

    The following document involves mixed content, so JAXB makes you explicitly call this out. Normally mixed is used with @XmlAnyElement so that get a list of everything elements and text so that order can be maintained.

    <phone-number type="TYPE">
        555-1111
        <phone-type>Cell</phone-type>
    </phone-number>
    

    You are receiving the exception due to the following in your OXM file:

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

    As the exception states you are not allowed to map a field/property with @XmlElement if another field/property in the class is mapped with @XmlValue

    What you Need to Do Instead

    You are really trying to map an element with mixed content. You can do so with the mapping file below:

    <java-type name="PhoneNumber">
        <java-attributes>
            <xml-attribute java-attribute="type" />
            <xml-any-element java-attribute="number" xml-mixed="true"/>
            <xml-element java-attribute="phoneType" name="phone-type" />
        </java-attributes>
    </java-type>
    

    FULL EXAMPLE

    oxm.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
        package-name="forum11988974">
        <java-types>
            <java-type name="PhoneNumber">
                <xml-root-element name="phone-number"/>
                <java-attributes>
                    <xml-attribute java-attribute="type" />
                    <xml-any-element java-attribute="number" xml-mixed="true"/>
                    <xml-element java-attribute="phoneType" name="phone-type" />
                </java-attributes>
            </java-type>
        </java-types>
    </xml-bindings>
    

    Demo

    package forum11988974;
    
    import java.io.File;
    import java.util.*;
    import javax.xml.bind.*;
    import org.eclipse.persistence.jaxb.JAXBContextProperties;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            Map<String, Object> properties = new HashMap<String, Object>();
            properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, "forum11988974/oxm.xml");
            JAXBContext jc = JAXBContext.newInstance(new Class[] {PhoneNumber.class}, properties);
    
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            File xml = new File("src/forum11988974/input.xml");
            PhoneNumber phoneNumber = (PhoneNumber) unmarshaller.unmarshal(xml);
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.marshal(phoneNumber, System.out);
        }
    
    }
    

    input.xml/Output

    <?xml version="1.0" encoding="UTF-8"?>
    <phone-number type="TYPE">555-1111<phone-type>Cell</phone-type></phone-number>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting this error message with the code below: class Money { public: Money(float
I have the below class I want to unit test: public class MyClass {
Does making the below class final (adding public final class) have any real impact
i need Enumarable value from below class but give error public static Enumerable LoadDataByName(string
i have the codes below class ReservationController extends Zend_Controller_Action { public function init() {
Is the below class immutable: final class MyClass { private final int[] array; public
If I have a class as below: class MyClass<T,U> { public void DoSomething(T t)
Please see the example code below: class A { private: class B { public:
I want this below class to return IList<> Please tell me why it is
I have a worker class like the one below: class Worker{ public: int Do(){

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.