package models;

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

@Entity
@Table(name = "groups")
public class Group {
    @Id
    @GeneratedValue
    @Column(name = "group_id")
    private long id;

    @Column
    private String name;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(nullable = false)
    private GroupType type;

    @Column
    private String description;

    @OneToOne(fetch = FetchType.LAZY)
    private File photo;

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

    @OneToMany(mappedBy = "group", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    private List<Post> posts = new ArrayList<>();

    public long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public GroupType getType() {
        return type;
    }

    public void setType(GroupType type) {
        this.type = type;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public File getPhoto() {
        return photo;
    }

    public void setPhoto(File photo) {
        this.photo = photo;
    }

    public List<Person> getMembers() {
        return members;
    }

    public List<Post> getPosts() {
        return posts;
    }
}

@@ -21,78 +21,368 @@
 ort 
-javax.persistence.*;%0Aimport java.util.ArrayList;%0Aimport java.util.List
+modules.preloader.DatabasePreloader;%0Aimport utils.SimpleQuery;%0A%0Aimport javax.persistence.*;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Random;%0Aimport java.util.concurrent.ThreadLocalRandom;%0A%0Aimport static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;%0Aimport static org.apache.commons.lang3.text.WordUtils.capitalizeFully
 ;%0A%0A@
@@ -1950,11 +1950,1049 @@
 s;%0A    %7D
+%0A%0A    static %7B%0A        DatabasePreloader.addTest((em -%3E %7B%0A            for (int i = 0; i %3C 100; i++) %7B%0A                Group group = new Group();%0A                String groupName = capitalizeFully(randomAlphabetic(10));%0A                group.setName(groupName);%0A                GroupType groupType;%0A                if(i %3E 50)  groupType = em.find(GroupType.class, GroupType.DefaultTypes.social);%0A                else  groupType = em.find(GroupType.class, GroupType.DefaultTypes.conversation);%0A                group.setType(groupType);%0A                String description = capitalizeFully(randomAlphabetic(20));%0A                group.setDescription(description);%0A                List%3CPerson%3E people = (new SimpleQuery(em, Person.class)).getResultList();%0A                int random = new Random().nextInt(people.size());%0A                ThreadLocalRandom.current().ints(0, people.size()).distinct().limit(random).forEach(index -%3E group.members.add(people.get(index)));%0A                em.persist(group);%0A            %7D%0A        %7D), 30);%0A%0A    %7D
 %0A%7D%0A

Add Group generator