I am farily new to Hibernate and here i am stuck with a transientexception. Please help.
Exception occured while saving the object Location
object references an unsaved--transient instance - save the transient instance before flushing: <City object>; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing
I am getting above exeption when i am trying to save data into my location table which has a City object with all its elements referring to null.
Location object
private String LocationAddress;
@ManyToOne
@JoinColumn(name = "CITYID")
private City city;
City
private String cityName;
private int cityId;
In Location table CityID
is nullable field because city
is not a required field. And we have a city table which is a static table so we dont want to insert data in City table.
Now when we are storing Location object. It stores data fine if City object has some values like some city. But throws exception when object contains a blank object(cityName
and cityId
are null)
Please help.
Example scenario
Successful
Location
locationAddress = "test Address"
city
cityId="1"
cityName="testCity"
Failure
Location
locationAddress = "test Address"
city
cityId=null
cityName=null