 <p><strong>The Problem</strong></p> <p>I'm assuming that you are using JPA to get your data as objects that can be handled by JAXB. If this is the case the JPA objects may be using lazy loading meaning that a query may not realize all the data at once. However as the JAXB implementation traverses the object graph, more and more of it is brought into memory until you run out.</p> <p><strong>Option #1 - Provide Data in Chunks</strong></p> <p>One approach is to return your data in chunks and offer a URI like the one below:</p> <ul> <li><a href="http://www.example.com/customers?start=10&amp;size=100" rel="nofollow">http://www.example.com/customers?start=10&amp;size=100</a></li> </ul> <p>These parameters tie in very nicely to JPA query settings:</p> <pre><code>namedQuery.setFirstResult(10); namedQuery.setMaxResults(100); </code></pre> <p><strong>Option #2 - Provide Links to Get More Data</strong></p> <p>Alternatively, instead of including all the data you can provide links to get more. For example instead of:</p> <pre><code>&lt;purchase-order&gt; &lt;product id="1"&gt; &lt;name&gt;...&lt;/name&gt; &lt;price&gt;...&lt;/price&gt; ... &lt;/product&gt; &lt;product id="2"&gt; &lt;name&gt;...&lt;/name&gt; &lt;price&gt;...&lt;/price&gt; ... &lt;/product&gt; ... &lt;/purchase-order&gt; </code></pre> <p>You could return the following, the client can then request details on products using the provided URI. You can map this in JAXB using an XmlAdapter.</p> <pre><code>&lt;purchase-order&gt; &lt;product&gt;http://www.example.com/products/1&lt;/product&gt; &lt;product&gt;http://www.example.com/products/2&lt;/product&gt; ... &lt;/purchase-order&gt; </code></pre> <p>For more information on XmlAdapter see:</p> <ul> <li><a href="http://bdoughan.blogspot.com/2010/07/xmladapter-jaxbs-secret-weapon.html" rel="nofollow">http://bdoughan.blogspot.com/2010/07/xmladapter-jaxbs-secret-weapon.html</a></li> </ul>