Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Boot项目中的MongoDB一对多和多对一关系_Spring_Spring Boot_Spring Data_Embedded Documents_Mangodb - Fatal编程技术网

Spring Boot项目中的MongoDB一对多和多对一关系

Spring Boot项目中的MongoDB一对多和多对一关系,spring,spring-boot,spring-data,embedded-documents,mangodb,Spring,Spring Boot,Spring Data,Embedded Documents,Mangodb,请告诉我如何在mongoDB中添加关系,因为我刚刚开始使用它。例如,注释id是外键: @Document class Comment { @Id private String id; private String text; private String author; // constructors, getters and setters are ommited } @Docume

请告诉我如何在mongoDB中添加关系,因为我刚刚开始使用它。例如,注释id是外键

 @Document
    class Comment {

        @Id
        private String id;
        private String text;
        private String author;

        // constructors, getters and setters are ommited
    }

    @Document
    class Article {
        @Id
        private String id;
        @DBRef(lazy = true)
        @CascadeSave
        private List<Comment> comments;
        private String title;
        private String text;

        // constructors, getters and setters are ommited
    }
@文档
课堂评论{
@身份证
私有字符串id;
私有字符串文本;
私有字符串作者;
//构造函数、getter和setter是常用的
}
@文件
班级文章{
@身份证
私有字符串id;
@DBRef(lazy=true)
@级联保存
私人名单评论;
私有字符串标题;
私有字符串文本;
//构造函数、getter和setter是常用的
}

JPA注释@OneToMany和@ManyToMany的等效性为@DBRef

JPA注释@OneToMany和@ManyToMany的等效性为@DBRef