title: how to prevent hibernate to insert into one table in many to many mapping
body: <p>I'm creating user profile in which user can enter their interests where interest is predefined list user can not select out of this list.</p>
  
  <p>i have User and Interest tables with primary key <code>userId</code> and <code>interestId</code> respectively.</p>
  
  <pre><code>             Table:User
  -------------------------------------
          userId      userName
            1            aaaa
            2            bbbb
            3            cccc
  </code></pre>
  
  <p>and</p>
  
  <pre><code>           Table:Intrest
  -------------------------------------
        interestId    interestName
            1            Sports
            2            Reading
            3            Music
  </code></pre>
  
  <p>Many to Many mapping table</p>
  
  <pre><code>         Table:UserIntrest
  -------------------------------------
          userId    interestId
            1            1
            1            2
            1            3
  </code></pre>
  
  <p><strong>here is my code</strong>  </p>
  
  <p><strong>User.java</strong></p>
  
  <pre><code>@Entity
  public class User {
      @Id 
      @GeneratedValue(strategy=GenerationType.AUTO)
      private long userId;
      private String username;
      private String password;
  
      @ManyToMany(cascade=CascadeType.ALL)
      @JoinTable(
          name="UserIntrest",
          joinColumns={ @JoinColumn(name="userId",referencedColumnName="userId") },
          inverseJoinColumns={ @JoinColumn(name="intrestId", referencedColumnName="intrestId") }
          )
      private List&lt;Intrest&gt; intrestList;
  
      ----- Getters Setters -----
  </code></pre>
  
  <p><strong>Intrest.java</strong></p>
  
  <pre><code>@Entity
  @Table(name="intrest")
  public class Intrest {
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int intrestId;
      private String intrestName;
  
      public Intrest(String name){
          this.intrestName = name;
      }
  ----- Getters &amp; Setters -----
  </code></pre>
  
  <p><strong>ActionClass.java</strong></p>
  
  <pre><code>public class ActionClass extends ActionSupport {
  
  
      private User user;
      private List&lt;String&gt; intrestList;//for get list of intrest from jsp select tag
      private List&lt;Intrest&gt; intrestLst = new ArrayList&lt;Intrest&gt;();
  
      public String execute(){
          for(int i = 0;i&lt;intrestList.size();i++){
              System.out.print(intrestLst.add(new Intrest(intrestList.get(i))));
          }
          user.setIntrestList(intrestLst);
  
          SessionFactory sf = new Configuration().configure().buildSessionFactory();
          Session session = sf.getCurrentSession();
          session.beginTransaction();
          session.save(user);
          session.getTransaction().commit();
  
  
          return SUCCESS;
      }
  
      ----- Getters &amp; Setters -----
  </code></pre>
  
  <p>so when i run this it insert user in User table selected interests in Interest table and mapping in UserInterest Table</p>
  
  <p>everything is ok but i don't need to insert interest in interest table because i already insert required interests.</p>
  
  <pre><code>Hibernate: insert into User (password, username) values (?, ?)
  Hibernate: insert into intrest (intrestName) values (?)
  Hibernate: insert into intrest (intrestName) values (?)
  Hibernate: insert into intrest (intrestName) values (?)
  Hibernate: insert into intrest (intrestName) values (?)
  Hibernate: insert into UserIntrest (userId, intrestId) values (?, ?)
  Hibernate: insert into UserIntrest (userId, intrestId) values (?, ?)
  Hibernate: insert into UserIntrest (userId, intrestId) values (?, ?)
  Hibernate: insert into UserIntrest (userId, intrestId) values (?, ?)
  </code></pre>
  
  <p>I don't want to execute </p>
  
  <pre><code>Hibernate: insert into intrest (intrestName) values (?)
  Hibernate: insert into intrest (intrestName) values (?)
  Hibernate: insert into intrest (intrestName) values (?)
  Hibernate: insert into intrest (intrestName) values (?)
  </code></pre>
  
  <p>queries.</p>
  
  <p>I search lots of for this problem but i can't find any solution.  </p>