package models;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = "messages")
public class Message {
    @Id
    @GeneratedValue
    @Column(name = "message_id", nullable = false)
    private int id;

    @ManyToOne(fetch = FetchType.LAZY)
    private Message parent;

    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<Message> comments = new ArrayList<>();

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    private Person author;

    @Temporal(TemporalType.TIMESTAMP)
    @Column
    private Date timestamp;

    @Column(length = 10000)
    private String body;

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name = "tags",
            joinColumns = {@JoinColumn(name = "message_id")},
            inverseJoinColumns = {@JoinColumn(name = "person_id")}
    )
    private List<Person> tags = new ArrayList<>();


    public int getId() {
        return id;
    }

    public Message getParent() {
        return parent;
    }

    public void setParent(Message parent) {
        this.parent = parent;
    }

    public List<Message> getComments() {
        return comments;
    }

    public Person getAuthor() {
        return author;
    }

    public void setAuthor(Person author) {
        this.author = author;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public List<Person> getTags() {
        return tags;
    }
}

@@ -986,16 +986,589 @@
 t%3C%3E();%0A%0A
+    @ManyToMany(fetch = FetchType.LAZY)%0A    @JoinTable(%0A            name = %22upvotes%22,%0A            joinColumns = %7B@JoinColumn(name = %22message_id%22)%7D,%0A            inverseJoinColumns = %7B@JoinColumn(name = %22person_id%22)%7D%0A    )%0A    private List%3CPerson%3E upvotes = new ArrayList%3C%3E();%0A%0A    @ManyToMany(fetch = FetchType.LAZY)%0A    @JoinTable(%0A            name = %22message_attachments%22,%0A            joinColumns = %7B@JoinColumn(name = %22message_id%22)%7D,%0A            inverseJoinColumns = %7B@JoinColumn(name = %22person_id%22)%7D%0A    )%0A    private List%3CPerson%3E messageAttachment = new ArrayList%3C%3E();%0A
 %0A    pub

Add ManyToMany Relation in Message model