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

  • Home
  • SEARCH
  • 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 7838791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:12:47+00:00 2026-06-02T15:12:47+00:00

I am new to Jaxb and this is my first time using it. I

  • 0

I am new to Jaxb and this is my first time using it. I have an xml that I would like it to be translated into my existing objects. I succeeded with simple attributes and elements, however with collections I am getting empty collections back.

I want to generate a Copyright Holder instance with an xml. I create an http post method to send the xml and use annotations to unmarshall it. To generate the post method I am using an firefox plugin called Poster. All collections from CopyrightHolder fail to load. (PS:Contracts collection is not mapped). The call to the post method works, the copyright holder is created but with all collections empty. I think I’m missing something with the annotations.

Any help is appreciated.

Classes:

CopyrightHolderContacts:

 @XmlRootElement(name="Contact", namespace="http://www.example.org/common")
 //@XmlType(name="Contact", namespace="http://www.example.org/common")
 public class CopyHolderContacts implements Contact, Serializable {



    private Long idContact;
    private CopyrightHolder copyrightHolder;
    private String name;
    private String email;
    private String office;
    private String work;
    private String mobile;
    private Boolean notify;

    public CopyHolderContacts() {
    }

    public CopyHolderContacts(CopyrightHolder copyrightHolder, String name, String email) {
        this.copyrightHolder = copyrightHolder;
        this.name = name;
        this.email = email;
    }

    public CopyHolderContacts( CopyrightHolder copyrightHolder, String name, String email, String office,
            String work, String mobile, Boolean notify ) {
        this.copyrightHolder = copyrightHolder;
        this.name = name;
        this.email = email;
        this.office = office;
        this.work = work;
        this.mobile = mobile;
        this.notify = notify;
    }

    @XmlTransient
    public Long getIdContact() {
        return this.idContact;
    }

    public void setIdContact( Long idContact ) {
        this.idContact = idContact;
    }

    @XmlTransient
    public CopyrightHolder getCopyrightHolder() {
        return this.copyrightHolder;
    }

    public void setCopyrightHolder(CopyrightHolder copyrightHolder) {
        this.copyrightHolder = copyrightHolder;
    }

    @XmlAttribute
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlAttribute
     public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @XmlAttribute(name="phoneOffice")
    public String getOffice() {
        return this.office;
    }

    public void setOffice(String office) {
        this.office = office;
    }

    @XmlAttribute(name="phoneWork")
    public String getWork() {
        return this.work;
    }

    public void setWork(String work) {
        this.work = work;
    }

    @XmlAttribute(name="phoneMobile")
    public String getMobile() {
        return this.mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    @XmlAttribute
    public Boolean getNotify() {
        return this.notify;
    }

    public void setNotify(Boolean notify) {
        this.notify = notify;
    }

   }

CopyrightHolder:

import static javax.persistence.GenerationType.SEQUENCE;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlTransient;

import org.hibernate.annotations.Cascade;


@XmlRootElement(name="CopyrightHolder", namespace="http://www.example.org/copyrightholder")
@XmlSeeAlso(CopyHolderContacts.class)
@Entity
public class CopyrightHolder implements Serializable {

    private Long idCopyrightHolder;
    private String name;
    private String address;
    private String affiliation;
    private Set<CopyHolderDocuments> copyHolderDocuments = new HashSet<CopyHolderDocuments>( 0 );
    private Set<CopyHolderContacts> copyHolderContacts = new HashSet<CopyHolderContacts>( 0 );
    private Set<Contract> contracts = new HashSet<Contract>( 0 );
    private Set<CustomLicFieldValue> copyHolderCustomLicFieldValues = new HashSet<CustomLicFieldValue>( 0 );
    private List<XMLCustomField> customFields;

    public CopyrightHolder() {
    }

    public CopyrightHolder( String name, String address, String affiliation ) {
        this.name = name;
        this.address = address;
        this.affiliation = affiliation;
    }

    public CopyrightHolder( String name, String address, String affiliation,
            Set<CopyHolderDocuments> copyHolderDocuments, Set<CopyHolderContacts> copyHolderContacts,
            Set<Contract> contracts, Set<CustomLicFieldValue> customLicFieldValues ) {
        this.name = name;
        this.address = address;
        this.affiliation = affiliation;
        this.copyHolderDocuments = copyHolderDocuments;
        this.copyHolderContacts = copyHolderContacts;
        this.contracts = contracts;
        this.copyHolderCustomLicFieldValues = customLicFieldValues;
    }

    @XmlTransient
    public Long getIdCopyrightHolder() {
        return this.idCopyrightHolder;
    }

    public void setIdCopyrightHolder( Long idCopyrightholder ) {
        this.idCopyrightHolder = idCopyrightholder;
    }

    @XmlAttribute
    public String getName() {
        return this.name;
    }

    public void setName( String name ) {
        this.name = name;
    }

    @XmlElement(name="Address", namespace="http://www.example.org/copyrightholder")
    public String getAddress() {
        return this.address;
    }

    public void setAddress( String address ) {
        this.address = address;
    }

    @XmlAttribute    
    public String getAffiliation() {
        return this.affiliation;
    }

    public void setAffiliation( String affiliation ) {
        this.affiliation = affiliation;
    }

    @XmlElementWrapper(name="Documents")
    @XmlElement(name="Document")    
    public Set<CopyHolderDocuments> getCopyHolderDocuments() {
        return this.copyHolderDocuments;
    }

    public void setCopyHolderDocuments( Set<CopyHolderDocuments> copyHolderDocuments ) {
        this.copyHolderDocuments = copyHolderDocuments;
    }

    @XmlElementWrapper(name="Contacts", namespace="http://www.example.org/common")
    @javax.xml.bind.annotation.XmlElement(name="Contact", namespace="http://www.example.org/common")
    public Set<CopyHolderContacts> getCopyHolderContacts() {
        return this.copyHolderContacts;
    }

    public void setCopyHolderContacts( Set<CopyHolderContacts> copyHolderContacts ) {
        this.copyHolderContacts = copyHolderContacts;
    }

    @XmlTransient    
    public Set<Contract> getContracts() {
        return this.contracts;
    }

    public void setContracts( Set<Contract> contracts ) {
        this.contracts = contracts;
    }

    @XmlTransient
    public Set<CustomLicFieldValue> getCopyHolderCustomLicFieldValues() {
        return this.copyHolderCustomLicFieldValues;
    }

    public void setCopyHolderCustomLicFieldValues( Set<CustomLicFieldValue> customLicFieldValues ) {
        this.copyHolderCustomLicFieldValues = customLicFieldValues;
    }

    @Transient
    @XmlElementWrapper(name="custom-fields")
    @XmlElement(name="custom-field")
    public List<XMLCustomField> getCustomFields() {
        return customFields;
    }

    public void setCustomFields(List<XMLCustomField> customFields) {
        this.customFields = customFields;
    }

}

The XML that I send:

<?xml version="1.0" encoding="UTF-8"?>
<CopyrightHolder affiliation="ingest" name="ingest" xmlns="http://www.example.org/copyrightholder" xmlns:cm="http://www.example.org/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/copyrightholder copyrightholder2.xsd ">
  <Address>Address</Address>
  <Contacts>
    <cm:Contact email="ingest2@ingest.com" name="ingest" notify="true" phoneMobile="" phoneOffice="" phoneWork=""/>
  </Contacts>
  <Documents>
    <cm:FilePath>cm:FilePath</cm:FilePath>
  </Documents>
  <CustomFields>
    <cm:CustomField name="ingest" order="0" required="false" type="Alphanumeric" value=""/>
  </CustomFields>
</CopyrightHolder>

Xsds:

common.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.example.org/common" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cm="http://www.example.org/common">
    <xsd:complexType name="contact">
        <xsd:sequence></xsd:sequence>

        <xsd:attribute name="name" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:minLength value="1"></xsd:minLength>
                    <xsd:maxLength value="50"></xsd:maxLength>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="email" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:pattern value="\w+@\w+"></xsd:pattern>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="phoneOffice" type="xsd:string" use="optional"></xsd:attribute>
        <xsd:attribute name="phoneWork" type="xsd:string" use="optional"></xsd:attribute>
        <xsd:attribute name="phoneMobile" type="xsd:string" use="optional"></xsd:attribute>
        <xsd:attribute name="notify" type="xsd:boolean" use="optional"></xsd:attribute>

    </xsd:complexType>

    <xsd:complexType name="documents">
        <xsd:sequence>
            <xsd:element name="FilePath" type="xsd:string" minOccurs="1" maxOccurs="unbounded">
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="custom-field">
        <xsd:sequence></xsd:sequence>
        <xsd:attribute name="name" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:minLength value="1"></xsd:minLength>
                    <xsd:maxLength value="50"></xsd:maxLength>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="required" type="xsd:boolean" use="optional" default="false">
        </xsd:attribute>
        <xsd:attribute name="type" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="Alphanumeric"></xsd:enumeration>
                    <xsd:enumeration value="Date"></xsd:enumeration>
                    <xsd:enumeration value="Number"></xsd:enumeration>
                    <xsd:enumeration value="Percentage"></xsd:enumeration>
                    <xsd:enumeration value="Text"></xsd:enumeration>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="order" type="xsd:int" use="optional"></xsd:attribute>
        <xsd:attribute name="value" type="xsd:string" use="required"></xsd:attribute>
    </xsd:complexType>

     <xsd:complexType name="contacts">
        <xsd:sequence>
            <xsd:element name="Contact" type="cm:contact" minOccurs="1" maxOccurs="unbounded"></xsd:element>
        </xsd:sequence>
    </xsd:complexType>

      <xsd:complexType name="custom-fields">
        <xsd:sequence>
            <xsd:element name="CustomField" minOccurs="1" maxOccurs="unbounded" type="cm:custom-field"></xsd:element>
        </xsd:sequence>
    </xsd:complexType>

</xsd:schema>

copyrightholder.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.example.org/copyrightholder" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org/copyrightholder" xmlns:cm="http://www.example.org/common">


    <xsd:import namespace="http://www.example.org/common" schemaLocation="common.xsd"></xsd:import>
    <xsd:complexType name="CopyrightHolder">
        <xsd:sequence>

            <xsd:element name="Address" type="xsd:string" minOccurs="1" maxOccurs="1"></xsd:element>
            <xsd:element name="Contacts" type="cm:contacts" minOccurs="0" maxOccurs="1">
            </xsd:element>
            <xsd:element name="Documents" type="cm:documents" minOccurs="0" maxOccurs="1">
            </xsd:element>
            <xsd:element name="CustomFields" type="cm:custom-fields" minOccurs="0" maxOccurs="1">
            </xsd:element>
        </xsd:sequence>


        <xsd:attribute name="name" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:minLength value="1"></xsd:minLength>
                    <xsd:maxLength value="50"></xsd:maxLength>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="affiliation" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:minLength value="1"></xsd:minLength>
                    <xsd:maxLength value="50"></xsd:maxLength>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
    </xsd:complexType>

    <xsd:element name="CopyrightHolder" type="CopyrightHolder"></xsd:element>
</xsd:schema>
  • 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-02T15:12:48+00:00Added an answer on June 2, 2026 at 3:12 pm

    Your namespaces are messed up. For example:

    @XmlElementWrapper(name="Contacts", namespace="http://www.example.org/common")
    @javax.xml.bind.annotation.XmlElement(name="Contact", namespace="http://www.example.org/common")
    public Set<CopyHolderContacts> getCopyHolderContacts() {
        return this.copyHolderContacts;
    }
    

    In your XML document, the Contacts wrapper element has the http://www.example.org/copyrightholder namespace.

    Try changing it to

    @XmlElementWrapper(name="Contacts", namespace="http://www.example.org/copyrightholder")
    @XmlElement(name="Contact", namespace="http://www.example.org/common")
    

    And similarly for the other collections.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <xs:msgdata xmlns:xs=http://www.myCompany.com
We're parsing an XML document using JAXB and get this error: [org.xml.sax.SAXParseException: Invalid byte
I'm using JAXB to generate XML that is uploaded to our Google feed. While
We are using JAXB Annotations on our model objects that we return from our
I have an xml like this: <todo> <doLaundry cost=1/> <washCar cost=10/> <tidyBedroom cost=0 experiencePoints=5000/>
I'm using BeanUtils to manipulate Java objects created via JAXB, and I've run into
This is the first time I am working this intensly with XML in Java.
I'm using JAXB with Scala, my marshalling code looks like this: def marshalToXml(): String
Using latest JAXB (Sun) and have a hierarchy of schemas that use import directives
I'm working with a XML structure that looks like this: <ROOT> <ELEM_A> <A_DATE>20100825</A_DATE> <A_TIME>141500</A_TIME>

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.