(SOLVED) “object references an unsaved transient instance”

How to fix the Hibernate “object references an unsaved transient instance – save the transient instance before flushing” error !

SOLUTION : You should include on your collection mapping:

(if using xml)

cascade ="all"

or (if using annotations)


This happens because you have a collection in your entity, and that collection has one or more items which are not present in the database. By specifying the above options you tell hibernate to save them to the database when saving their parent.

For more information about the JPA/Hibernate Cascade type : read this tutorial “JPA and Hibernate Cascade Types“. You can also watch this video .

Marwen Mselmi
Author: Marwen Mselmi

Founder of Javatuto.com, love Java and open source stuff. Follow me on Linkedin.

Leave a comment