1

Spring-boot 2.1.4, Spring-Data-Mongo 2.1.6, DuplicateKeyException when I load and re-save lazy loaded content.

@Document
public class User {
   @Id
   private String id;
   @Version
   private Long version;
   @DBRef(lazy = true)
   private Role role;
}

@Document
public class Role {
    @Id
    private String id;
    @Version
    private Long version;  
}
User user = userRepository.findById("1234");
roleRepository.save(user.getRole()); //org.springframework.dao.DuplicateKeyException

It works without lazy=true

lollito
  • 11
  • 4

0 Answers0