Please try the approach mentioned in below stack overflow post.
How to fix the Hibernate "object references an unsaved transient instance - save the transient instance before flushing" error