title: Object references an unsaved transient instance save the transient instance before flushing:
body: <p><img src="https://i.stack.imgur.com/qEP51.png" alt="Relation of table"></p>
  
  <p>The diagram shown above shows relation between tables.</p>
  
  <p>The <strong>AddressType</strong>  table contain static values such as <em>mailing</em>, <em>home</em>, <em>work</em> etc. </p>
  
  <p>In <strong>AddressTypeRel</strong> model class I'm having an <strong>AddressType</strong> object with annotation many to one</p>
  
  <p>AddressTypeRel.java</p>
  
  <pre><code>public class AddressTypeRel implements java.io.Serializable{
  .......
  
  private AddressType addressType=new AddressType();
  .......
  
  @ManyToOne()
  @LazyCollection(LazyCollectionOption.FALSE)
  @JoinColumn(name="typeId", insertable=false, updatable=false, nullable=false)
  @NotFound(action = NotFoundAction.IGNORE)
  public AddressType getAddressType() {
     return addressType;
  }
  
  public void setAddressType(AddressType addressType) {
     this.addressType = addressType;
  }
  ......
  }
  </code></pre>
  
  <p>After saving into <strong>Address</strong> table I should also save the <em>type</em>(<em>mailing/billing</em>) of address and <em>addressId</em> into <strong>AddressTypeRel</strong> but I'm not able to save. While I try to save</p>
  
  <pre><code>AddressTypeRel addressTypeRel=new AddressTypeRel();
  addressTypeRel.setAddressId(i) //i=5 for example
  addressTypeRel.setTypeId(j)    //j=4 for example
  hibernatetemplate.save(addressTypeRel);
  </code></pre>
  
  <p>The error occuring is :</p>
  
  <blockquote>
    <p>object references an unsaved transient instance - save the transient
    instance before flushing: com.sample.AddressType</p>
  </blockquote>