Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+9 votes
4 views
in Java by (50.2k points)

I receive the following error when I save the object using Hibernate.

object references an unsaved transient instance - save the transient instance before flushing.

How can we solve this error?

1 Answer

+10 votes
by (107k points)
This error happens because you have a collection in your entity, and that collection has one or more items that are not present in the database. By specifying either of the below statements, you tell hibernate to save them to the database when saving their parent.

You have to add cascade="all" (if using xml) or cascade=CascadeType.ALL (if using annotations) on your collection mapping.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...