title: Spring JPA mongodb using annotations
body: <p>Help me understand this. I am using spring-data-mongodb without hibernate or any other jpa provider. My domain model is like this:</p>
  
  <pre><code>public class User {
    @Id
    private String id;
    private String username;
    private String password;
    ...
  }
  </code></pre>
  
  <p>I run a test class to populate a few users in my mongodb, which works fine. But if I add a few more annotations like this:</p>
  
  <pre><code>public class User {
    @Id
    private String id;
    @Field(value="uname") private String username;
    @Field(value="pass")private String password;
    ...
  }
  </code></pre>
  
  <p>my test class adds just one user, the next one throws exception complaining of duplicate entries - </p>
  
  <blockquote>
    <p>org.springframework.dao.DuplicateKeyException: E11000 duplicate key error index: gldata.user.$username_-1  dup key: { : null }; nested exception is com.mongodb.MongoException$DuplicateKey: E11000 duplicate key error index: gldata.user.$username_-1  dup key: { : null }</p>
  </blockquote>
  
  <p>What am I missing here?</p>