Hibernate (annotation): Error: TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing

March 27th, 2009 by jeremychone

If you get an error like this one

Hibernate: Error: TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing..

It is probably because you did not annotate your ManyToOne with the Hibernate SAVE_UPATE Cascade annotation:

@ManyToOne()
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
public Category getCategory() {
        return category;
}

Note, putting only

@ManyToOne(cascade = {CascadeType.MERGE,CascadeType.PERSIST})
public Category getCategory() {

Will not resolve the issue.

Leave a Reply