title: Hibernate with annotations: "Repeated column in mapping fo entity" - Composite PK
body: <p>First of all I'd like to thank everyone that's even reading this.</p>
  
  <p>I'm having a problem with the Hibernate fw in my application. The following figure shows the diagram of the part of the database thats causing the error.</p>
  
  <p><a href="https://i.stack.imgur.com/aCYYl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aCYYl.jpg" alt="Diagram"></a><br>
  <sub>(source: <a href="https://fbcdn-sphotos-a-a.akamaihd.net/hphotos-ak-ash3/74777_707832512567265_1426711129_n.jpg" rel="nofollow noreferrer">akamaihd.net</a>)</sub>  </p>
  
  <p>My code was generated autmatically by the reverse engineering, and to make it work I had to  "show" the code generator that the module_application table is not a many-to-many table (using a cutom reverse engineering strategy). Now, when I run my code, I get the following error:</p>
  
  <pre><code>Error creating Session: org.hibernate.MappingException: Repeated column in mapping for entity: DAL.module_application.ModuleApplication column: application_id (should be mapped with insert="false" update="false")
  </code></pre>
  
  <p>The ModuleApplication class is as shown below:</p>
  
  <pre><code>@Entity
  @Table(name = "module_application", catalog = "domotics")
  public class ModuleApplication implements java.io.Serializable
  {
  
      /**
       * 
       */
      private static final long serialVersionUID = 4725933797587110677L;
      private ModuleApplicationId id;
      private Application application;
      private Module module;
      private Set&lt;ModuleApplicationStatus&gt; moduleApplicationStatuses = new HashSet&lt;ModuleApplicationStatus&gt;(0);
  
      public ModuleApplication()
      {
      }
  
      public ModuleApplication(ModuleApplicationId id, Application application, Module module)
      {
          this.id = id;
          this.application = application;
          this.module = module;
      }
  
      public ModuleApplication(ModuleApplicationId id, Application application, Module module, Set&lt;ModuleApplicationStatus&gt; moduleApplicationStatuses)
      {
          this.id = id;
          this.application = application;
          this.module = module;
          this.moduleApplicationStatuses = moduleApplicationStatuses;
      }
  
      @EmbeddedId
      @AttributeOverrides(
      {
          @AttributeOverride(name = "networkAddress", column = @Column(name = "network_address", nullable = false, length = 45)),
          @AttributeOverride(name = "applicationId", column = @Column(name = "application_id", nullable = false)) 
      })
      public ModuleApplicationId getId()
      {
          return this.id;
      }
  
      public void setId(ModuleApplicationId id)
      {
          this.id = id;
      }
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "application_id", nullable = false, insertable = false, updatable = false)
      public Application getApplication()
      {
          return this.application;
      }
  
      public void setApplication(Application application)
      {
          this.application = application;
      }
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "network_address", nullable = false, insertable = false, updatable = false)
      public Module getModule()
      {
          return this.module;
      }
  
      public void setModule(Module module)
      {
          this.module = module;
      }
  
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "moduleApplication")
      public Set&lt;ModuleApplicationStatus&gt; getModuleApplicationStatuses()
      {
          return this.moduleApplicationStatuses;
      }
  
      public void setModuleApplicationStatuses(Set&lt;ModuleApplicationStatus&gt; moduleApplicationStatuses)
      {
          this.moduleApplicationStatuses = moduleApplicationStatuses;
      }
  }
  </code></pre>
  
  <p>As we can see, both insert and update are set to false. If anyone knows the exact cause of this error  and/or how to solve it, please share the knowledge!</p>