[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[eclipselink-dev] How can I get the child entitites on a XML marshalling using @XmlID and @XmlIDREF annotations. I only get the parent entity and not the children nodes.
|
- From: André Moutinho <moutinho@xxxxxxxxx>
- Date: Wed, 28 Sep 2011 13:15:09 -0300
- Delivered-to: eclipselink-dev@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=s73kt72zohyKy2u48hgQ1gVYEyU+lpS2Ck2qV075pYI=; b=PUPSrC2frkeCI1kF4RXd469iujowYyKSyDHQn9LinDt46gyprDgC6x12nUo+5Rhq+b 5dd8IckO5EPzYVSwsHec6Wzzz6KmeIoLFlXoz9thMf0j3kCOktO4Ae+AG/CgtE8rs9R9 53QmGMKnNxkwQNB9xd7vKmFG/N//dpOhCPFv4=
Hello all,
I want to generate an XML file of an object tree with 1:N
relashionship. I am using the @XmlID and @XmlIDREF annotations. The
entity "construtora" has N "empreendimentos" entitites related.
The root class is :
class ConstrutoraImpl {
@XmlID
private long id;
String nome;
String contato;
String telefone;
@XmlIDREF
@XmlList
private List<Empreendimento> empreendimentos;
}
class Empreeendimento {
@XmlID
private long id:
String nome;
String endereco;
private Construtora construtora;
}
The java code to generate the XML file is:
JAXBContext context = (JAXBContext) JAXBContext.newInstance(new
Class[]{ConstrutoraImpl.class, EmpreendimentoImpl.class});
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(construtora, System.out);
The resulting XML file is:
<?xml version="1.0" encoding="UTF-8"?>
<construtora>
<id>75</id>
<empreendimentos>74 75</empreendimentos>
<contato>contato1</contato>
<nome>nome1</nome>
<telefone>telefone1</telefone>
</construtora>
The "empreendimentos" child entities are missing. How can I generate a
XML with all the child entitites and the root entity?
All the Best,
André Moutinho