Java Spring mongodb@DBRef自身

Java Spring mongodb@DBRef自身,java,spring,mongodb,spring-security,Java,Spring,Mongodb,Spring Security,是否可以将@DBRef添加到引用他自己的列表中。我想一个例子可以解释我的问题: @Document(collection = "user") public class User { @Indexed(unique = true, direction = IndexDirection.DESCENDING, dropDups = true) private final String uname; ... @DBRef private List<

是否可以将@DBRef添加到引用他自己的列表中。我想一个例子可以解释我的问题:

@Document(collection = "user")
public class User {
    @Indexed(unique = true, direction = IndexDirection.DESCENDING, dropDups = true)
    private final String uname;

    ...

    @DBRef 
    private  List<User>  contacts; // <-- The Problem

    ... (Getter / Setters, etc.)

}
是否可以修复我的代码,或者我必须为引用创建一个新文档

编辑:

我现在有一个奇怪的问题。为了进行测试,我在用户类中注释了contacts变量

@Document(collection = "user")
public class User {

    @Id
    private final   String      uid;

    @Indexed(unique = true, direction = IndexDirection.DESCENDING, dropDups = true)
    private final   String      uname;

    ...

    //private  List<String>  contacts;

    @DBRef private  Role        role;

    ...

}
如果联系人列表未被注释,$contacts.uname从何而来?我已经重新启动mongodb服务器并删除了我的收藏

@Document(collection = "user")
public class User {

    @Id
    private final   String      uid;

    @Indexed(unique = true, direction = IndexDirection.DESCENDING, dropDups = true)
    private final   String      uname;

    ...

    //private  List<String>  contacts;

    @DBRef private  Role        role;

    ...

}
duplicate key error index: test.user.$contacts.uname  dup key: { : null }" , "code" : 11000}