I have one to many mapping in my Pojo classes. A shop has a branch and a branch has many shops Here's Shop's Code:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="Shop")
public class Shop {
@XmlID
private String name;
@XmlIDREF
@XmlElement(name="ShopBranch",type=Branch.class)
private Branch branch;
//Getter Setter
}
Below is Branch Code:
 @XmlAccessorType(XmlAccessType.FIELD)
public class Branch {
@XmlID
private String name;
private String address;
@XmlIDREF
@XmlElement(nillable=false,required=true)
private List<Shop> shops;
//Getter and Setters
}
I'm publishing a webservice with some basic methods. and my wsimport is generating Branch class as below
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "branch", propOrder = {
    "branchName",
    "address",
    "branchShop"
})
public class Branch {
    @XmlElement(name = "BranchName")
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    @XmlID
    @XmlSchemaType(name = "ID")
    protected String branchName;
    protected String address;
    @XmlElementRef(name = "BranchShop", type = JAXBElement.class)
    protected List<JAXBElement<Object>> branchShop;
    //Getter-Setter
    }
I have no idea why it is List<JAXBElement<Object>> and not List<JAXBElement<Shop>>. But anyway. I have a method which returns all branches and that is working fine. When i extract branchShop from branch's instance i'm getting correct size for branchShop list but for all of the items in list getValue is returning NULL. Below is brief code:
PencilCatalog service= new PencilCatalog();
com.pencilhouse.webservices.PencilService port=service.getPencilCatalogPort();
((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, Constant.PENCIL_SERVICE);
    List<Branch> branches= port.getAllBranches();
for(Branch b:branches)
{
    System.out.println("******************Branch:"+b.getBranchName()+" "+b.getAddress()+"******************");
    JAXBElement<Object>o=b.getBranchShop().get(0);
    System.out.println(o+"Value"+o.getScope()+" "+o.getValue());
}
o/p
******************Branch:KukatPalli Steer 2 Kukatpalli****************** javax.xml.bind.JAXBElement@45d9d7beValueclass com.pencilhouse.webservices.Branch null
The WSDL generated is quite large. I'm posting only type of Branch and Shop. I'm publishing webservice using Endpoint
XML generated:
<xs:complexType name="shop">
<xs:sequence>
<xs:element name="name" type="xs:ID" minOccurs="0"/>
<xs:element name="ShopBranch" type="xs:IDREF" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="branch">
<xs:sequence>
<xs:element name="BranchName" type="xs:ID" minOccurs="0"/>
<xs:element name="address" type="xs:string" minOccurs="0"/>
<xs:element name="BranchShop" type="xs:IDREF" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
Intercepted Information: Request:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getAllBranches xmlns:ns2="PencilServiceHouse"/>
</S:Body>
</S:Envelope>
Response:
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:getAllBranchesResponse xmlns:ns2="PencilServiceHouse">
        <return>
            <name>
                    KukatPalli
            </name>
            <address>
                    Steer 2 Kukatpalli
            </address>
            <shops>
                    Pencil World    <!-- This is Shop Information which is coming as NULL in java, This is Shop's Name field which is declared as id using @XmlId -->
            </shops>
            <shops>
                    Pencils Den
            </shops>
            <shops>
                    Pencils Bag
            </shops>
        </return>
        <return>
            <name>
                    Salt Lake
            </name>
            <address>
                    Sec V Salt Lake
            </address>
            <shops>
                    Pencil World
            </shops>
            <shops>
                    Pencils Den
            </shops>
        </return>
        <return>
            <name>
                    Noida
            </name>
            <address>
                    Noida Sec 43
            </address>
            <shops>
                    Pencils Bag
            </shops>
        </return>
        </ns2:getAllBranchesResponse>
    </S:Body>
</S:Envelope>
 
     
    