The diagram shown above shows relation between tables.
The AddressType table contain static values such as mailing, home, work etc.
In AddressTypeRel model class I'm having an AddressType object with annotation many to one
AddressTypeRel.java
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;
}
......
}
After saving into Address table I should also save the type(mailing/billing) of address and addressId into AddressTypeRel but I'm not able to save. While I try to save
AddressTypeRel addressTypeRel=new AddressTypeRel();
addressTypeRel.setAddressId(i) //i=5 for example
addressTypeRel.setTypeId(j) //j=4 for example
hibernatetemplate.save(addressTypeRel);
The error occuring is :
object references an unsaved transient instance - save the transient instance before flushing: com.sample.AddressType