I receive following error when I save the object using Hibernate
object references an unsaved transient instance - save the transient instance before flushi
I also faced the same situation. By setting following annotation above the property made it solve the exception prompted.
The Exception I faced.
Exception in thread "main" java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.model.Car_OneToMany
To overcome, the annotation I used.
@OneToMany(cascade = {CascadeType.ALL})
@Column(name = "ListOfCarsDrivenByDriver")
private List listOfCarsBeingDriven = new ArrayList();
What made Hibernate throw the exception:
This exception is thrown at your console because the child object I attach to the parent object is not present in the database at that moment.
By providing @OneToMany(cascade = {CascadeType.ALL})
, it tells Hibernate to save them to the database while saving the parent object.