@@ -0,0 +1,2516 @@
+package com.vladmihalcea.hibernate.masterclass.laboratory.mapping;%0A%0Aimport com.vladmihalcea.hibernate.masterclass.laboratory.util.AbstractTest;%0Aimport org.junit.Test;%0A%0Aimport javax.persistence.*;%0Aimport java.util.*;%0A%0A/**%0A * ManyToManyWithElementCollectionTest - ManyToMany with ElementCollection Test%0A *%0A * @author Vlad Mihalcea%0A */%0Apublic class ManyToManyWithElementCollectionTest extends AbstractTest %7B%0A%0A    @Override%0A    protected Class%3C?%3E%5B%5D entities() %7B%0A        return new Class%3C?%3E%5B%5D %7B%0A            Clubber.class,%0A            Club.class%0A        %7D;%0A    %7D%0A%0A    @Test%0A    public void testAddingEmbeddable() %7B%0A        doInTransaction(session -%3E %7B%0A            Clubber clubber = new Clubber();%0A            Club club = new Club();%0A            clubber.addClub(club);%0A        %7D);%0A    %7D%0A%0A    @Entity(name = %22Clubber%22)%0A    public static class Clubber%7B%0A%0A        @Id%0A        @GeneratedValue%0A        @Column(name = %22Clubber_Id%22)%0A        private Integer id;%0A%0A        @Temporal(TemporalType.TIMESTAMP)%0A        @ElementCollection%0A        @CollectionTable(name=%22CLUB_ASSIGNMENTS%22, joinColumns=@JoinColumn(name=%22Clubber_Id%22, referencedColumnName=%22Clubber_Id%22))%0A        @Column(name=%22CLUB_DATE%22)%0A        @MapKeyJoinColumn(name = %22Club_ID%22, referencedColumnName=%22Club_ID%22)%0A        private Map%3CClub, Date%3E joinDate = new HashMap%3C%3E();%0A%0A        @ManyToMany(cascade = CascadeType.PERSIST)%0A        @JoinTable(name = %22CLUB_ASSIGNMENTS%22,%0A                joinColumns = @JoinColumn(name=%22Clubber_Id%22, referencedColumnName=%22Clubber_Id%22),%0A                inverseJoinColumns = @JoinColumn(name=%22Club_ID%22, referencedColumnName=%22Club_ID%22))%0A        private List%3CClub%3E clubs = new ArrayList%3C%3E();%0A%0A%0A        public Integer getId() %7B%0A            return id;%0A        %7D%0A%0A        public Map%3CClub, Date%3E getJoinDate() %7B%0A            return joinDate;%0A        %7D%0A%0A        public List%3CClub%3E getClubs() %7B%0A            return clubs;%0A        %7D%0A%0A        public void addClub(Club club) %7B%0A            joinDate.put(club, new Date());%0A            clubs.add(club);%0A            club.getClubbers().add(this);%0A        %7D%0A    %7D%0A%0A    @Entity(name = %22Club%22)%0A    public static class Club %7B%0A%0A        @Id%0A        @GeneratedValue%0A        @Column(name = %22Club_ID%22)%0A        private Integer id;%0A%0A        @ManyToMany(cascade = CascadeType.PERSIST, mappedBy = %22clubs%22)%0A        private List%3CClubber%3E clubbers = new ArrayList%3C%3E();%0A%0A        public Integer getId() %7B%0A            return id;%0A        %7D%0A%0A        public List%3CClubber%3E getClubbers() %7B%0A            return clubbers;%0A        %7D%0A    %7D%0A%7D%0A

Add @ManyToMany with @ElementCollection test