Kindth
Kindth

Reputation: 337

MongoDB One-to-Many and Many-to-One relations in Spring Boot Project

please how can I add relations in a mongoDB cause I just start using it. For example Comment id is a foreign key:

 @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
    }

Upvotes: 1

Views: 7748

Answers (1)

Kindth
Kindth

Reputation: 337

The equivalence of the JPA annotation @OneToMany and @ManyToMany is @DBRef

Upvotes: 3

Related Questions