tags:

views:

1677

answers:

1

I receive following error when i save the object using hibernate

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

Can you help me ?

+7  A: 

You should include cascade="all" (if using xml) or cascade=CascadeType.ALL (if using annotations) on your collection mapping.

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.

Bozho
thanks dude it works
Tushar Ahirrao
Isn't this implicit? Wouldn't you always want Hibernate to save them?
Marcus
@Marcus - no, it's not. You may want to handle them manually.
Bozho