title: Spring Mongo DB @DBREF
body: <p>I am having trouble writing code that would allow get a user and claim details in a straightforward way. This is my MongoDB structure,</p>
  <pre><code>db.user.find();
  </code></pre>
  <pre><code>user: 
      {
      &quot;name&quot; : &quot;KSK&quot;, 
       &quot;claim&quot;  : [objectId(&quot;52ffc4a5d85242602e000000&quot;),objectId(&quot;52ffc4a5d85242602e000001&quot;)] 
      }
  
  claim: 
  
      [
         {
           &quot;_id&quot; : &quot;52ffc4a5d85242602e000001&quot;,
           &quot;claimName&quot; :&quot;XXXX&quot;
         },
         {
           &quot;_id&quot; : &quot;52ffc4a5d85242602e000000&quot;,
           &quot;claimName&quot; :&quot;YYY&quot;
         }
      ]
  </code></pre>
  <p>My Entity class is:</p>
  <pre><code>@Document(collection=&quot;user&quot;)
  public  class User{
      @Id      
      private String id;
      private String name; 
      @DBRef
      private List&lt;Claim&gt; claim; 
      // setter and getter   
  }
  </code></pre>
  <p>Claim Class:</p>
  <pre class="lang-java prettyprint-override"><code>@Document(collection=&quot;Claim&quot;)
  public class Claim{
      @Id 
      private String id; 
      private String claimName;   
  }
  </code></pre>
  <p>I have a  method to get the users by name like below,</p>
  <pre class="lang-java prettyprint-override"><code>public User findByName(String name);
  </code></pre>
  <p>If I try to hit this method am getting an error that,</p>
  <p>No converter found capable of converting from type <code>org.bson.types.ObjectId</code> to type <code>java.lang.String</code></p>
  <p>So I changed my User entity class as like below,</p>
  <p>Instead of  <code>private List&lt;Claim&gt; claim</code>;</p>
  <p>Changed as <code>Private List&lt;ObjectId&gt; claim</code>;</p>
  <p>Now if I execute a method(findByName), I get a user object that has both claimed object ids <code>(&quot;52ffc4a5d85242602e000001&quot;,&quot;52ffc4a5d85242602e000000&quot;)</code>, then iterate the claim list and get the claim details corresponding to the claim object Id.</p>
  <p>Instead of doing this, when I execute <code>findByName</code> method I want to get a user and claim details. How can I achieve this functionality?</p>