Spring-data-mongodb DbRef Lazy с @Version вызывает org.springframework.dao.DuplicateKeyException - PullRequest
1 голос
/ 16 мая 2019

Spring-boot 2.1.4, Spring-Data-Mongo 2.1.6, DuplicateKeyException при загрузке и повторном сохранении ленивого загруженного контента.

@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

Работает без lazy = true

...