title: Insertion failure on table , make a new entry on foreign table also
body: <p>I am using postgres database with hibernate as an ORM. 
  I have a table named district with foreign key division.</p>
  
  <p>But after insertion, it makes new entry both on division and district table. At first, it makes a new entry on division table (new id is created at that time). Then it makes new entry on district table with the new id of division. </p>
  
  <pre><code>CREATE TABLE district(   
    id SERIAL,    
    division_id INTEGER REFERENCES division(id),   
    name varchar(30),   
    PRIMARY KEY (id) 
  );
  </code></pre>
  
  <p><strong>This is my model:</strong></p>
  
  <pre><code>@Entity
  @Table(name = "district")
  public class District implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name="id")
      private Integer id;
  
      @ManyToOne(cascade = {CascadeType.ALL})
      @JoinColumn(name="division_id")
      private Division division;
  
      @Column(name="name")
      private String name;
      // getter setter
  </code></pre>
  
  <p><strong>My controller:</strong></p>
  
  <pre><code>@GetMapping(value = "/createdistrict")
  public ModelAndView  createdistrict(Locale locale, Model model) {
  
      List&lt;Division&gt; allDivisionList = new ArrayList&lt;Division&gt;();
      allDivisionList = this.districtService.listdivisions() ;
      Map&lt;Integer,String&gt; allDivision = new LinkedHashMap&lt;Integer,String&gt;();
      for( int i=0 ; i &lt; allDivisionList.size() ; i++) {
  
          allDivision.put(allDivisionList.get(i).getId() , allDivisionList.get(i).getName());
      }
  
      return new ModelAndView("createdistrict" , "allDivision" , allDivision);
  }
  </code></pre>
  
  <p><strong>DAO:</strong>        </p>
  
  <pre><code>@Override
  public void adddistrict(District p) {
     Session session = this.sessionFactory.getCurrentSession();
     session.saveOrUpdate(p);
     logger.info("District saved successfully, Phone Details=" + p);
  }
  </code></pre>
  
  <p><strong>my jsp page:</strong></p>
  
  <pre><code> &lt;tr&gt;
                      &lt;td&gt;
                          Division 
                      &lt;/td&gt;
                      &lt;td&gt;
                      &lt;select id="division" name="division"&gt;
                            &lt;c:forEach items="${allDivision}" var="allDivision"&gt;
                            &lt;option value="${allDivision.key}"&gt;${allDivision.value }&lt;/option&gt;
                            &lt;/c:forEach&gt;
                      &lt;/select&gt; 
                      &lt;/td&gt; 
                    &lt;/tr&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/EcUVy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EcUVy.png" alt="create district page"></a></p>