title: Hibernate: Insert issue - Parent Key not found
body: <p>I am facing issue inserting an entity into database. I am using Hibernate JPA.
  Here is my database structure :</p>
  
  <pre><code>Table : User {CGU_USER_ID as PK}
  Table : Industries {CGI_INDUSTRY_ID (PK),CGI_INDUSTRY_NAME}
  Table : USER_INDUSTRY_MAP {CUIM_USER_ID (FK),CUIM_INDUSTRY_ID (FK)}
  </code></pre>
  
  <p>Here is my Mapping :</p>
  
  <pre><code>@JoinTable(name = "USER_INDUSTRY_MAP", joinColumns = @JoinColumn(name = "CUIM_USER_ID", referencedColumnName = "CGU_USER_ID"), inverseJoinColumns = @JoinColumn(name = "CUIM_INDUSTRY_ID"))
  @OneToMany(cascade = { CascadeType.MERGE, CascadeType.REMOVE }, fetch = FetchType.EAGER)
  private List&lt;Industry&gt; industrySet;
  </code></pre>
  
  <p>The Exception i am getting says :</p>
  
  <pre><code>org.springframework.dao.DataIntegrityViolationException: could not insert collection: [com.keff.gg.domain.User.industrySet#1242]; SQL [insert into CG_USER_INDUSTRY_MAP (CUIM_USER_ID, CUIM_INDUSTRY_ID) values (?, ?)]; constraint [CUSTOMERGATEWAY.FK_CUIM_USER_ID]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert collection: [com.keff.gg.domain.User.industrySet#1242]
  
  Caused by: java.sql.SQLException: ORA-02291: integrity constraint (CUSTOMERPROJECT.FK_CUIM_USER_ID) violated - parent key not found
  </code></pre>
  
  <p>Here is my insert code:</p>
  
  <pre><code>User user = new User();
  query = session.createQuery("from Industry industry where industry.industryName=:industryName");
          query.setParameter("industryName", "validIndstry");
          results = (List&lt;?&gt;) query.list();
          if(results != null &amp;&amp; results.size()&gt;0){
              industryList = (List&lt;Industry&gt;)results;
          }
  user.setIndustrySet(industryList); // If this is set to null then insert into User table is successfull
  Long id = (Long) hibernateTemplate.save(user);
  </code></pre>
  
  <p>Can somebody look at my mappings and tell me what i am doing wrong. 
  Please help me out. I am very very new to hibernate. Please let me know if more information is required to trace the issue.</p>
  
  <p>UPDATE -------------------------------------------------------------------------------------
  I have tried Making the relationship Many to many and bidirectional </p>
  
  <pre><code>//User Class
  @JoinTable(name = "CG_USER_INDUSTRY_MAP", joinColumns = @JoinColumn(name = "CUIM_USER_ID", referencedColumnName = "CGU_USER_ID"), inverseJoinColumns = @JoinColumn(name = "CUIM_INDUSTRY_ID"))
  @ManyToMany(cascade = { CascadeType.MERGE, CascadeType.REMOVE }, fetch = FetchType.EAGER)
  private List&lt;Industry&gt; industrySet;
  
  //Industry Class
  @ManyToMany(fetch = FetchType.LAZY, mappedBy = "industrySet")
  private List&lt;User&gt; userSet;
  </code></pre>
  
  <p>But still getting the same issue. </p>