簡體   English   中英

Spring Boot項目中MongoDB的一對多和多對一關系

[英]MongoDB One-to-Many and Many-to-One relations in Spring Boot Project

請問如何在 mongoDB 中添加關系,因為我剛開始使用它。 例如Comment 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
    }

JPA 注釋@OneToMany 和@ManyToMany 的等效項是@DBRef

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM