Hibernate projection property whole object
<p>I have a case like this:
<code>Class Foo</code> with two children (<code>A</code> and <code>B</code>), each being <code>Objects</code>.
In Hibernate, if I want to return only a list of the children, I would use projections on my criteria:</p>
<pre><code>criteria.setProjection(Projections.property(&quot;A&quot;));
</code></pre>
<p>This gives me a list of <code>A objects</code>, but they are all <code>lazy</code> loaded. As soon as I try to access anything other than the <code>id</code>, obviously things go wrong.
My <code>SQL</code> query indeed shows it:</p>
<pre><code>select A from Foo ...
</code></pre>
<p>Logically, only my id is filled in, and not the rest of my properties. How do I solve this problem so I get a list of <code>A objects</code> that have everything filled in?
I tried this:</p>
<pre><code>criteria.setResultTransformer(Transformers.aliasToBean(A.class));
</code></pre>
<p>but without success.</p>