title: Mongo Spring Data "foreign" key
body: <p>I'm using <a href="http://www.springsource.org/spring-data/mongodb" rel="nofollow">Spring Data</a> to manage my MongoDB database.</p>
  
  <p>On one collection I have 2 ObjectId fields, _id and one other that references an instance from another collection.</p>
  
  <p>My collection's class is like:</p>
  
  <pre><code>public class CollectionA
  {
  private ObjectId id;
  private String collectionADescription
  private ObjectId collectionBId
  }
  </code></pre>
  
  <p>with the class specified like this I am able to insert the "foreign key" sucessfully as an $oid.</p>
  
  <p>The problem is that I am getting the following binding error:</p>
  
  <blockquote>
    <p>Field error in object 'collectionA' on field 'collectionBId': rejected
    value []; codes
    [typeMismatch.collectionA.collectionBId,typeMismatch.collectionBId,typeMismatch.org.bson.types.ObjectId,typeMismatch];
    arguments
    [org.springframework.context.support.DefaultMessageSourceResolvable:
    codes [collectionA.collectionBId,collectionBId]; arguments []; default
    message [collectionBId]]; default message [Failed to convert property
    value of type 'java.lang.String' to required type
    'org.bson.types.ObjectId' for property 'collectionBId'; nested
    exception is java.lang.IllegalStateException: Cannot convert value of
    type [java.lang.String] to required type [org.bson.types.ObjectId] for
    property 'collectionBId': no matching editors or conversion strategy
    found]</p>
  </blockquote>
  
  <p>If I set the collectionBId variable to String the variables are inserted as string instead of $oid</p>
  
  <p>How can I accomplish this?</p>
  
  <p>Thans</p>