title: Spring JPA (Hibernate) auto-flatten nested objects into single table
body: <p>I used to know how to do this but for the life of me can't even remember what to google for! I have a bunch of POJOs with a handful of simple fields (primitives, Strings, etc) each, and I want to just add them all into a parent POJO and store the whole lot together as a single row in a single table (without having to duplicate and copy every field from the child POJOs into the parent POJO). I believe there is an annotation, or perhaps a Hibernate converter, that I can use to do this very easily?</p>
  
  <p>As an example, say I have:</p>
  
  <pre><code>class A {
    Integer foo;
    String bar;
  }
  class B {
    Integer lol;
    String rofl;
  }
  </code></pre>
  
  <p>I want a parent object like:</p>
  
  <pre><code>@Entity
  class P {
    A a;
    B b;
  }
  </code></pre>
  
  <p>Which will have a database schema of <code>foo,bar,lol,rofl</code></p>
  
  <p>Any help much appreciated!</p>