org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance beforeQuery flushing ?

+1 vote
1,251 views
asked May 23, 2018 by Hitesh Garg (352 points)  

I am trying to save the object using hibernate and getting the below error -

org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance beforeQuery flushing : xx.yy.zzz.ClassName.parentNode -> xx.yy.zzz.ClassName

How to solve this issue?

1 Answer

+1 vote
answered May 23, 2018 by Rahul Singh (553 points)  
selected May 23, 2018 by Hitesh Garg
 
Best answer

This means you are using a hibernate mappings like @OneToOne or @OneToMany.
Now for xml configuration you should include cascade="all" or for class based annotations cascade=CascadeType.ALL on your collection mapping.

This happens because you have a collection in your entity which has some elements which are not persisted in the database yet and hence it gives the error.
By mentioning the cascading types in your entity you tell hibernate to save all the child entities on saving the parent entity.

Welcome to Codingeek Q&A, where you can ask questions and receive answers from other members of the community.
...