title: Spring Hibernate ManyToMany
body: <p>I have 2 tables, VIDEO, VIDEOCATEGORY and joining table VIDEO2VIDEOCATEGORY. 
  I am trying to make many to many annotation. There is no error or warning in compilation. </p>
  
  <p>Database is empty in the begining. I try to persist Video entity(with list of VideoCategory)..at this time is all correect. New video is added to database. Some new categories are added as well. Then I try to add new video with new unique categories ...correct as well. Problem is when I try to add new Video with categories already existing in DB. Before this attempt I have 2 record in VIDEO2VIDEOCATEGORY ("cat1", 3) and ("cat2", 3) ...after attemp there should be 2 new records - ("cat1", 4) and ("cat2", 4) and 2 existing ("cat1", 3) and ("cat2", 3) but those old are not in DB. They were rewritten by 2 new records. </p>
  
  <p>How to solve it?
  My codes: </p>
  
  <pre><code>
  
     import java.io.Serializable;
      import java.util.List;
  
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.JoinTable;
      import javax.persistence.ManyToMany;
  
      import org.hibernate.annotations.Cascade;
  
  
      @Entity
      public class VideoCategory implements Serializable{
  
          private static final long serialVersionUID = -722840296120424003L;
  
          @Id 
          @Column(name = "id", unique = true, nullable = false)
          private String id;
  
  
          @ManyToMany(fetch=FetchType.EAGER)
          @Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
          @JoinTable(name = "video2videocategory",
                joinColumns = {@JoinColumn(name = "cat_id")}, inverseJoinColumns =       @JoinColumn(name = "vid_id"))
            private List videos;
  
  
          public VideoCategory(){
          }
  
          public VideoCategory(String id) {
              super();
              this.id = id;
          }
          public String getId() {
              return id;
          }
          public void setId(String id){
              this.id = id;
          }
          public List getVideos() {
              return videos;
          }
          public void setVideos(List videos) {
              this.videos = videos;
          }
  
          @Override
          public String toString() {
              return "VideoCategory [id=" + id + ", videos=" + videos + "]";
          }
      }
  
  
      import java.io.Serializable;
      import java.util.Date;
      import java.util.List;
  
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.EnumType;
      import javax.persistence.Enumerated;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.JoinTable;
      import javax.persistence.ManyToMany;
      import javax.persistence.SequenceGenerator;
      import javax.persistence.JoinColumn;
  
      import org.hibernate.annotations.Cascade;
  
  
  
      @Entity
      @SequenceGenerator(
          name="VID_SEQ_GEN",
          sequenceName="VIDSEQ",
          allocationSize=1
      )
      public class Video implements Serializable {
  
          private static final long serialVersionUID = 2284488937952510797L;
  
          @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="VID_SEQ_GEN")
          @Column(name = "id", unique = true, nullable = false)
          private Long id;
  
          @Column(name = "title", unique = false, nullable = false)
          private String title;
  
          @Column(name = "video_path", unique = false, nullable = false)
          private String videoPath;
  
          @Column(name = "video_type", unique = false, nullable = false)
          @Enumerated(value=EnumType.STRING) 
          private VideoType videoType;
  
          @Column(name = "creation_date", unique = false, nullable = false)
          private Date creationDate;
  
          @ManyToMany
          @Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
           @JoinTable(name = "video2videocategory", 
                   joinColumns = {@JoinColumn(name = "vid_id")}, inverseJoinColumns = @JoinColumn(name = "cat_id"))
          private List categories;
  
  
  
          public Video(){
          }
  
  
          public Long getId() {
              return id;
          }
          public void setId(Long id) {
              this.id = id;
          }
          public String getTitle() {
              return title;
          }
          public void setTitle(String title) {
              this.title = title;
          }
          public String getVideoPath() {
              return videoPath;
          }
          public void setVideoPath(String videoPath) {
              this.videoPath = videoPath;
          }
          public VideoType getVideoType() {
              return videoType;
          }
          public void setVideoType(VideoType videoType) {
              this.videoType = videoType;
          }
          public Date getCreationDate() {
              return creationDate;
          }
          public void setCreationDate(Date creationDate) {
              this.creationDate = creationDate;
          }
          public List getCategories() {
              return categories;
          }
  
          public void setCategories(List categories) {
              this.categories = categories;
          }
  
          @Override
          public String toString() {
              return "Video [id=" + id + ", creationDate="
                      + creationDate + ", title=" + title
                      + ", videoPath=" + videoPath + ", videoType=" + videoType + "]";
          }
      }
  
  
  </code></pre>
  
  <p>I have tried both jpa and hibernate annotations.</p>
  
  <p>Please help.</p>