title: JAXB flatten list of entities when marshalling
body: <p>I'm using JPA/Hibernate as my persistence framework, and I have the following entity hierarchy:</p>
  
  <pre><code>@Entity
  @Table(name = "node")
  @XmlRootElement(name = "nodeMap")
  @XmlAccessorType(XmlAccessType.FIELD)
  public class NodeMapDTO {
  
      @XmlElementWrapper(name = "ipAddresses")
      @XmlElement(name = "ipAddress")
      @OneToMany
      @JoinColumn(name = "node_id")
      private List&lt;IPAddressDTO&gt; ipAddresses;
  
      [...]
  }
  
  @Entity
  @Table(name = "node_ip_address")
  @XmlAccessorType(XmlAccessType.FIELD)
  public class IPAddressDTO {
  
      @Column(name = "ip_address")
      private String ipAddress;
  
      [...]
  }
  </code></pre>
  
  <p>When I convert a NodeMapDTO into XML, I get the following result:</p>
  
  <pre><code>&lt;nodeMap&gt;
     &lt;ipAddresses&gt;
        &lt;ipAddress&gt;
           &lt;ipAddress&gt;192.59.233.20&lt;/ipAddress&gt;
        &lt;/ipAddress&gt;
     &lt;/ipAddresses&gt;
  &lt;/nodeMap&gt;
  </code></pre>
  
  <p>But I want it to be:</p>
  
  <pre><code>&lt;nodeMap&gt;
     &lt;ipAddresses&gt;
        &lt;ipAddress&gt;192.59.233.20&lt;/ipAddress&gt;
     &lt;/ipAddresses&gt;
  &lt;/nodeMap&gt;
  </code></pre>
  
  <p>I unfortunately need to have my <code>ipAddresses</code> field be a list of <code>IPAddressDTO</code>s instead of <code>String</code>s because otherwise I can't use the @OneToMany annotation (and no I don't want to use @ElementCollection for performance reasons).</p>
  
  <p>I'd also like to try to do this without having to create any extra wrapper classes. I think if I create a wrapper class for the <code>List&lt;IPAddressDTO&gt; ipAddresses</code> field, my Hibernate annotations won't work and it'll just make the code much more complex than it needs to be.</p>
  
  <p>Thank you all.</p>