title: Spring Data MongoDB identifier as object
body: <p>I have a java class that as the id has an object that holds the actual id value. How can I use Spring Data MongoDB for id generation and identification, and how to define the MongoDB repository?</p>
  
  <p>Example:</p>
  
  <pre><code>@Document
  class A {
    @Id
    private B id;
  
  }
  </code></pre>
  
  <pre><code>class B{
   private String id;
   private String idAppGenerator;
  }
  </code></pre>
  
  <p>This throws exception due to the fact that Spring can't autogenerate value for B class.</p>